使用jQuery从JSON/MYSQL更新表 [英] Updating table from JSON/MYSQL with jQuery

查看:117
本文介绍了使用jQuery从JSON/MYSQL更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇哪种最可接受/最有效的方法是将表与来自json的数据一起使用.

I'm curious as to what the most acceptable/effective approach is to using tables with data from json.

我有一个开发中的项目,需要基于mysql表更新表的单个单元格. 我的X轴标签将是各种日期(也从mysql中提取). Y轴标签是时间(它们始终相同,因此可以静态生成). 该表的内容将是可用的约会槽(也从mysql中提取).

I have one project in development where I need to update individual cells of a table, based on a mysql table. My X axis labels would be assorted dates (also pulled from mysql). The Y axis labels are times (These are always the same and as such could be generated statically). The content of the table would be available appointment slots (also pulled from mysql).

该表纯粹是从mysql读取的,因此确实需要更新该表.我需要每15秒刷新一次表内容(显然无需刷新页面).所以我的问题是引用每个单元格的最佳方法是什么,这样我就可以用json输出以编程方式更新它们.如果已经从约会花名册中删除了一天,则还需要具有删除列的功能.

This table is purely reading off of mysql, as such does need to update the table. I need to refresh the table contents every 15 seconds (without refreshing the page obviously). So my question what is the best way to give reference each cell so I can programatically update them with my json output. This would also need the ability to remove a column if a day has been removed from the appointment roster.

任何帮助都将是惊人的.

Any assistance would simply be amazing.

推荐答案

我认为主要功能是

  • javascript setTimeout()每15秒获取一次数据.
  • 客户端与客户端之间的一种哈希比较服务器数据以查看是否有修改
  • 仅提取要应用的修改的php函数
  • 用于更新JSON发送的约会的JavaScript
  • javascript setTimeout() to fetch data every 15sec.
  • a kind of hash comparison between client & server data to see if there is a modification
  • a php function that extract just the modifications to apply
  • a javascript to update the appointments sent by JSON

也许您应该使用日历工具进行渲染.
完整日历是一个很好的开源解决方案.

Maybe you should use a calendar tool for rendering.
Fullcalendar is a pretty good open-source solution for that.

对于更新,我将通过呈现如下数据来实现:

For the updates, I would approach this by presenting the data like:

appointment_id, timestamp_start, timestamp_end, ...

通过该操作,您可以知道约会是否已经存在或是否已进行修改(更新或删除)
您还可以推断出要显示的日期

With that you can know if the appointment already exists or if it's a modification (update or delete)
You can also deduce the dates to display

修改

由于您的桌子不是很大,并且总是基于日/小时,因此这将更易于管理:

Since your table is not that big and always day/hour based, this will be much simpler to manage:

Javascript setTimeout()每15秒获取一次数据,
通过JSON检索整个表,
通过使用jQuery构建HTML来加载它,例如:

Javascript setTimeout() to fetch data every 15sec,
Retrieve the entire table by JSON,
Load it by building up the HTML with jQuery like:

table = $('#table_container');
/* data -> appointments indexed by hours/days fetched by JSON
 * x -> days, y -> hours
 */
for (y=0; data[y].length; y++) {
  tr = $('<tr />');
  table.append(tr);
  for (x=0; data[y][x]; x++) {
    td = $('<td />');
    td.html(data[y][x]);
    tr.append(td);
  }
}

未经测试,但很粗略的想法

这篇关于使用jQuery从JSON/MYSQL更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆