1
我想從我的WebAPI返回以下JSON數據建立數據表:數據表無信息
{
"body": {
"recording": [],
"alarm": [{
"device_id": "someID",
"device_name": " ",
"channel_id": "1",
"start_time": "2016-08-21T16:15:57+03:00",
"timestamp": 1471785357,
"end_time": "2016-08-21T16:16:07+03:00",
"storage_key": "some string",
"duration": 10,
"expiration_time": 1474416000,
"file_name": "file name4",
"size": 703504,
"group_id": "some guid",
"event_type": "m",
"local_ttl": 2278752,
"thumbnail": null
}, {
"device_id": "someID",
"device_name": " ",
"channel_id": "1",
"start_time": "2016-08-21T16:15:57+03:00",
"timestamp": 1471785357,
"end_time": "2016-08-21T16:16:07+03:00",
"storage_key": "some string",
"duration": 10,
"expiration_time": 1474416000,
"file_name": "file name4",
"size": 703504,
"group_id": "some guid",
"event_type": "m",
"local_ttl": 2278752,
"thumbnail": null
}],
"guard_tour": [],
"continuous_event": []
},
"header": {
"request_id": "some id",
"response_status": "OK",
"message": "endpoint succeeded"
}
}
我建設我的數據表像這樣:
$("#alarmTable").DataTable({
ajax: {
url: 'myurl',
dataSrc: 'body.alarm'
}
});
,我發現了以下錯誤:datatables請求未知的參數0爲第0行0
也許有點更有經驗的眼睛會省下我幾個小時在搜索解決這個問題
編輯:我的HTML
<table id="alarmTable" class="table table-striped">
<thead>
<tr>
<th>Device ID</th>
<th>Device Name</th>
<th>Channel Id</th>
<th>Start Time</th>
<th>End Time</th>
<th>Duration</th>
<th>File Name</th>
<th>size</th>
<th>Event Type</th>
</tr>
</thead>
<tbody></tbody>
</table>
而且,我的網絡API是mearly代理,所以我真的不能改變我的JSON格式
哪裏是你的HTML嗎? – JPeG
檢查此鏈接,可能對您有所幫助: - http://stackoverflow.com/questions/7640204/how-to-load-the-local-json-variable-using-jquery-datatable。你的json結構也很奇怪!重新檢查它 –