html5 - datatables 加載不出來數(shù)據(jù)。
問題描述
我在后臺已經(jīng)請求到了json數(shù)據(jù),如下`
[{'aid':100000,'name':'JYCM201609010250','rtsp':'947|100000|3750','statuz':'1','updateTime':'2017-05-31'},{'aid':100001,'name':'gui','rtsp':'947|100000|3750','statuz':'0','updateTime':'2017-05-31'}]
下面是我的js 代碼
<script> $(document).ready(function () {$(’#table_id_example’).DataTable({ 'iDisplayLength': 10, 'bLengthChange': false, 'ajax': {'url': '/media','dataType': 'json','success': function (json) { console.log(json)} }, 'columns': [{ 'data': ’aid’},{ 'data': ’name’},{ 'data': ’rtsp’},{ 'data': ’statuz’},{ 'data': ’updateTime’} ]}); });</script>
后臺代碼
@Autowired private MediaImpl media; @ResponseBody @RequestMapping(value = '/media',method = RequestMethod.GET) public List<Media> MediaAll(){System.out.println('------------------------------------------------------');return media.findAll(); }
html代碼
<link rel='stylesheet' href='http://www.4tl426be.cn/css/jquery.dataTables.css' th:href='http://www.4tl426be.cn/wenda/@{css/jquery.dataTables.css}'/><script type='text/javascript' src='http://www.4tl426be.cn/js/jquery.min.js' th:src='http://www.4tl426be.cn/wenda/@{/js/jquery.min.js}'></script><script type='text/javascript' src='http://www.4tl426be.cn/js/jquery.dataTables.js' th:src='http://www.4tl426be.cn/wenda/@{js/jquery.dataTables.js}'></script><body><table cellspacing='0' width='100%'> <thead> <tr><th>媒資ID</th><th>媒資名稱</th><th>播放串</th><th>狀態(tài)</th><th>更新時間</th> </tr> </thead> <!-- <tbody> <tr><td>Row 1 Data 1</td><td>Row 1 Data 1</td><td>Row 1 Data 1</td><td>Row 1 Data 1</td><td>Row 1 Data 1</td> </tr></tbody>--></table></body>
前后臺都沒有報錯,但就是顯示不出來數(shù)據(jù)。請問是少配置還是那塊書寫錯誤,謝謝
問題解答
回答1:用過這個插件,你還要加一個datasrc說明,獲取成功之后,從哪提數(shù)據(jù)。(修正,可能不是datasrc的原因,但看著又像是沒加這個的原因)這是我用到的代碼,看是否能給你點啟示:`$.ajax({
type:’GET’,***/*省略某些代碼*/*** success:function(result){ /*聲明一個空對象*/ var returnData = {}; returnData.data = result.rows //數(shù)據(jù)來源 callback(returnData) //此步不能省略,最重要的就是調(diào)用callback }
})`
回答2:官網(wǎng)上對獲取的json數(shù)據(jù)有這種要求
By default DataTables will look for the property data (or aaData for compatibility with DataTables 1.9-) when obtaining data from an Ajax source or for server-side processing
也就是說你那個包含各個數(shù)據(jù)的數(shù)組應(yīng)該放在data屬性里,這樣應(yīng)該就可以了
{'data':[{'aid':100000,'name':'JYCM201609010250','rtsp':'947|100000|3750','statuz':'1','updateTime':'2017-05-31'},{'aid':100001,'name':'gui','rtsp':'947|100000|3750','statuz':'0','updateTime':'2017-05-31'}]}
data同級還可以放別的如條目總數(shù)等的參數(shù)
相關(guān)文章:
1. python 利用subprocess庫調(diào)用mplayer時發(fā)生錯誤2. python文檔怎么查看?3. python - Pycharm的Debug用不了4. javascript - 關(guān)于apply()與call()的問題5. datetime - Python如何獲取當(dāng)前時間6. javascript - nginx反向代理靜態(tài)資源403錯誤?7. html - eclipse 標(biāo)簽錯誤8. 請問PHPstudy中的數(shù)據(jù)庫如何創(chuàng)建索引9. 安全性測試 - nodejs中如何防m(xù)ySQL注入10. python - pycharm 自動刪除行尾空格
