问题:DataTables warning: Requested unknown parameter '0' from the data source for row '0'
代码:
<script type="text/javascript">var data = [{"Name":"UpdateBootProfile","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]},{"Name":"NRB Boot","Result":"PASS","ExecutionTime":"00:00:50.5000000","Measurement":[{"TestName":"TOTAL_TURN_ON_TIME","Result":"PASS","Value":"50.5","LowerLimit":"NaN","UpperLimit":"NaN","ComparisonType":"nctLOG","Units":"SECONDS"}]},{"Name":"NvMgrCommit","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]},{"Name":"SyncNvToEFS","Result":"PASS","ExecutionTime":"00:00:01.2500000","Measurement":[]} ];$(function() {var testsTable = $('#tests').dataTable({bJQueryUI: true,aaData: data,aoColumns: [{ mData: 'Name' },{ mData: 'Result' },{ mData: 'ExecutionTime' },
{ mData: 'localtion' }
] }); }); </script>
报错原因: 这个location字段,有数据的时候出现,没有数据的时候,就成这个样子了
aoColumns: [{ mData: 'Name' },{ mData: 'Result' },{ mData: 'ExecutionTime' }
导致页面错误。
改正的方法是:
1.$(
'#example'
).dataTable( {
"columns"
: [
null
,
null
,
null
,
{
"data"
:
"office"
,
// can be null or undefined
"defaultContent"
:
""
}
]
} ); 加上【"defaultContent"
:
""
】
2. 用都是数组的形式
var data = [["UpdateBootProfile","PASS","00:00:00",[]] ,["NRB Boot","PASS","00:00:50.5000000",[{"TestName":"TOTAL_TURN_ON_TIME","Result":"PASS","Value":"50.5","LowerLimit":"NaN","UpperLimit":"NaN","ComparisonType":"nctLOG","Units":"SECONDS"}]] ,["NvMgrCommit","PASS","00:00:00",[]] ,["SyncNvToEFS","PASS","00:00:01.2500000",[]]
];
解决链接:
https://datatables.net/manual/tech-notes/4
https://datatables.net/reference/option/columns.defaultContent
http://stackoverflow.com/questions/16539578/datatables-warning-requested-unknown-parameter-0-from-the-data-source-for-row