我使用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数据正在被正确获取.
我似乎在 …