如何将 JSON 数据放入 html/javascript 网格表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13012390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:38:34  来源:igfitidea点击:

How to put JSON data in html / javascript grid table

javascriptjqueryhtmljson

提问by mcknight

I have the following JSON-formatted data:

我有以下 JSON 格式的数据:

    [
{
    "ID": "00:50:c2:63:10:1a",
    "start": "1349773838277760",
    "end": "1349773838277770",
    "startArea": "areaStart",
    "endArea": "areaEnd",
    "duration": "10"
},
{
    "ID": "00:50:c2:63:10:1a",
    "start": "1349773838277760",
    "end": "1349773838277780",
    "startArea": "areaStart",
    "endArea": "areaEnd",
    "duration": "20"
},
{
    "ID": "00:50:c2:63:10:1a",
    "start": "1349773838277760",
    "end": "1349773838277780",
    "startArea": "areaStart",
    "endArea": "areaEnd",
    "duration": "20"
}]

How can I display this data nicely in a html data table?

如何在 html 数据表中很好地显示这些数据?

Is there a plugin for jQuery that can help me?

是否有 jQuery 插件可以帮助我?

My basic approach is this:

我的基本方法是这样的:

http://jsfiddle.net/LKkSJ/

http://jsfiddle.net/LKkSJ/

回答by Andy

I would recommend dataTables, you can feed in a javascript array. Click here

我会推荐 dataTables,你可以输入一个 javascript 数组。点击这里

回答by PKeidel

DataTablescan create a table from JSON.

DataTables可以从 JSON 创建一个表。

回答by Kernel James

If DataTables is too heavy for you (70 KB) you can use the various template libraries out there:

如果 DataTables 对您来说太重 (70 KB),您可以使用各种模板库:

Just convert a table row into a template and then repeat that template inside an HTML table.

只需将表格行转换为模板,然后在 HTML 表格中重复该模板即可。

回答by Kernel James

You can use jqGridfor jQuery.

您可以将jqGrid用于 jQuery。