有人知道,什么是错误的非常简单的HTML文件下面?
我只是试图使用an array of objects作为DataTables的数据源:
tests.html:
<html> <head> <link type="text/css" rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css"> <link type="text/css" rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/css/jquery.dataTables_themeroller.css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script> <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.min.js"></script> <script type="text/javascript"> var data = [ {"Name":"UpdateBootProfile","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]},{"Name":"NRB Boot","ExecutionTime":"00:00:50.5000000","Measurement":[{"TestName":"TOTAL_TURN_ON_TIME","Value":"50.5","LowerLimit":"NaN","UpperLimit":"NaN","ComparisonType":"nctLOG","Units":"SECONDS"}]},{"Name":"NvMgrCommit",{"Name":"SyncNvToEFS","ExecutionTime":"00:00:01.2500000","Measurement":[]} ]; $(function() { var testsTable = $('#tests').dataTable({ bJQueryUI: true,aaData: data,aoColumns: [ { mData: 'Name' },{ mData: 'Result' },{ mData: 'ExecutionTime' } ] }); }); </script> </head> <body> <table id="tests"> <thead> <tr> <th>Name</th> <th>Result</th> <th>ExecutionTime</th> </tr> </thead> <tbody> </tbody> </table> </body> </html>
更新:好的,我有作者to use a newer version of DataTables or rename mData to mDataProp的答案
解决方法
您正在使用对象数组。你可以使用二维数组吗?
http://www.datatables.net/examples/data_sources/js_array.html
见这个jsfiddle:http://jsfiddle.net/QhYse/
我使用像这样的数组,它工作正常:
var data = [ ["UpdateBootProfile","PASS","00:00:00",[]],["NRB Boot","00:00:50.5000000",[{"TestName":"TOTAL_TURN_ON_TIME","Units":"SECONDS"}]],["NvMgrCommit",["SyncNvToEFS","00:00:01.2500000",[]] ];
编辑以包括对象数组
这个问题有一个可能的解决方案:jQuery DataTables fnrender with objects
这个jsfiddle http://jsfiddle.net/j2C7j/使用一个对象数组。为了不得到错误,我不得不把它用3个空白值 – 不是最优的,我知道。你可以找到一个更好的方法与fnRender,请张贴如果你这样做。
var data = [ ["","",{"Name":"UpdateBootProfile","Measurement":[]} ] ]; $(function() { var testsTable = $('#tests').dataTable({ bJQueryUI: true,aoColumns: [ { mData: 'Name',"fnRender": function( oObj ) { return oObj.aData[3].Name}},{ mData: 'Result',"fnRender": function( oObj ) { return oObj.aData[3].Result }},{ mData: 'ExecutionTime',"fnRender": function( oObj ) { return oObj.aData[3].ExecutionTime } } ] }); });