DataTables警告:从'0'行的数据源请求的未知参数'0' [英] DataTables warning: Requested unknown parameter '0' from the data source for row '0'
问题描述
我只是想使用数据表数据源的数组//
测试.html:
< html>
< head>
< link type =text / css =stylesheethref =https://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css >
< link type =text / css =stylesheethref =https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/css/jquery.dataTables_themeroller.css >
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js>< / script>
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js>< / script>
< script type =text / javascriptsrc =https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.min.js>< /脚本>
< 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'}
]
} );
});
< / script>
< / head>
< body>
< table id =tests>
< thead>
< tr>
< th> Name< / th>
< th>结果< / th>
<执行时间< / th>
< / tr>
< / thead>
< tbody>
< / tbody>
< / table>
< / body>
< / html>
更新:好的,我有作者的答案< a href =http://datatables.net/forums/discussion/15519/requested-unknown-parameter-0390039-from-the-data-source-for-row-0390039 =noreferrer>使用较新的数据表版本或将mData重命名为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 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,[]]
];
编辑以包含对象数组
这个问题有一个可能的解决方案: jQuery DataTables fnrender with objects < a>
这个jsfiddle http://jsfiddle.net/j2C7j/ 使用一组对象。为了得不到错误,我不得不用3个空白值填补它 - 不太理想,我知道。你可以找到一个更好的方式与fnRender,请发布,如果你这样做。
var data = [
[,,,{Name:UpdateBootProfile ,Result:PASS,ExecutionTime:00:00:00,Measurement:[]}]
];
$(function(){
var testsTable = $('#tests')。dataTable({
bJQueryUI:true,
aaData:data,
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}}
]
});
});
Does anybody please know, what is wrong with the very simple HTML file below?
I am just trying to use an array of objects as the data source for 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","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' }
]
});
});
</script>
</head>
<body>
<table id="tests">
<thead>
<tr>
<th>Name</th>
<th>Result</th>
<th>ExecutionTime</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
UPDATE: Ok, I've got the answer from the author to use a newer version of DataTables or rename mData to mDataProp
You're using an array of objects. Can you use a two dimensional array instead?
http://www.datatables.net/examples/data_sources/js_array.html
See this jsfiddle: http://jsfiddle.net/QhYse/
I used an array like this and it worked fine:
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",[]]
];
Edit to include array of objects
There's a possible solution from this question: jQuery DataTables fnrender with objects
This jsfiddle http://jsfiddle.net/j2C7j/ uses an array of objects. To not get the error I had to pad it with 3 blank values - less than optimal, I know. You may find a better way with fnRender, please post if you do.
var data = [
["","","", {"Name":"UpdateBootProfile","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]} ]
];
$(function() {
var testsTable = $('#tests').dataTable({
bJQueryUI: true,
aaData: data,
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 } }
]
});
});
这篇关于DataTables警告:从'0'行的数据源请求的未知参数'0'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!