小编Car*_*rlM的帖子

将JSON对象加载到Datatable Jquery中的问题

我使用DataTables与Jquery,我有一个JSON我想通过获取对象数据源Ajax在表中和显示.

JSON数据从/live/log网址返回,格式如下:

{
    "Logs": [
        {
            "date": "2015-04-22T14:00:39.086Z",
            "eventType": "event1",
            "str": "Application startup"
        },
        {
            "date": "2015-04-22T14:01:27.839Z",
            "eventType": "event2",
            "str": "test Logged in"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的表格HTML:

<table id="example" class="display" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>Date</th>
      <th>Event</th>
      <th>Description</th>
    </tr>
  </thead>

  <tfoot>
    <tr>
      <th>Date</th>
      <th>Event</th>
      <th>Description</th>
    </tr>
  </tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)

最后JS用于获取和填充数据表:

$(document).ready(function() {
  $('#example').dataTable( {
    "ajax": "/live/log",
    "columns": [
        {"data": "date"},
        {"data": "eventType"},
        {"data": "str"}
      ]

  });
});
Run Code Online (Sandbox Code Playgroud)

我可以通过调试器看到JSON数据正在被正确获取.

我似乎在 …

javascript ajax datatable jquery json

3
推荐指数
1
解决办法
2367
查看次数

标签 统计

ajax ×1

datatable ×1

javascript ×1

jquery ×1

json ×1