我正在尝试使用 jQuery/DataTables 创建一个表,并使用 JSON 数据作为源。我已经验证了数据没问题。不幸的是,我不断收到此错误:“DataTables 警告(表 id='example'):从第 0 行的数据源请求未知参数 '1'”。我不确定我在这里做错了什么:
JSON
dataSet = [
{
"Month": "October",
"Notices Received": "0",
"Declined Participation": "0",
"Selected Field Reviews": "0",
"Selected File Review": "0",
"Pending": "0",
"Pending Previous Year": "0",
"Controversial": "0",
"GFP Reviews": "0",
"NAD Appeals": "0",
"Mediation Cases": "0",
"Monthly Cost Savings": "$0.00",
"Monthly Expenditure": "$0.00"
},
{
"Month": "November",
"Notices Received": "0",
"Declined Participation": "0",
"Selected Field Reviews": "0",
"Selected File Review": "0",
"Pending": "0",
"Pending Previous Year": "0",
"Controversial": "0",
"GFP Reviews": "0",
"NAD Appeals": "0",
"Mediation Cases": "0",
"Monthly Cost Savings": "$0.00",
"Monthly Expenditure": "$0.00"
},
{
"Month": "December",
"Notices Received": "0",
"Declined Participation": "0",
"Selected Field Reviews": "0",
"Selected File Review": "0",
"Pending": "0",
"Pending Previous Year": "0",
"Controversial": "0",
"GFP Reviews": "0",
"NAD Appeals": "0",
"Mediation Cases": "0",
"Monthly Cost Savings": "$0.00",
"Monthly Expenditure": "$0.00"
}];
JS:
$('#theJson').text(dataSet); //just for testing
$('#example').dataTable( {
"aaData": dataSet,
"aoColumns": [
{ "sTitle": "Month" },
{ "sTitle": "Notices Received" },
{ "sTitle": "Declined Participation" },
{ "sTitle": "Selected Field Reviews"},
{ "sTitle": "Selected File Reviews"},
{ "sTitle": "Pending"},
{ "sTitle": "Pending Previous Year"},
{ "sTitle": "Controversial"},
{ "sTitle": "GFP Reviews"},
{ "sTitle": "NAD Appeals"},
{ "sTitle": "Mediation Cases"},
{ "sTitle": "Monthly Cost Savings"},
{ "sTitle": "Monthly Expenditure"}
]
} );
HTML:
<table width="100%" id="example" border="0" cellspacing="0" cellpadding="0"></table>
我得到的只是错误消息和表头。页脚实际上显示:“显示 4,008 个条目中的 1 到 10 个”,这可能表明它正在查看数据。谢谢!
最佳答案
问题是“aaData”:dataSet,
接受数组数据,但你仍然没有转换json数据,
检查一下,
var dataSet = [ {//Table Data }, { //Table Data } , { //Table Data } ];//Wrong Type (Still Json Format)
但数据格式除外
var dataSet = [ [//Table Data ], [ //Table Data ] , [ //Table Data ] ];//Right Type (Now Array Format)
将json数据转换为数组数据
var dataSet=[];
$.each(o,function(i,k){
dataSet.push( $.map(o[i], function(el) { return el; }));
});
console.log(dataSet);
这里是他的演示... Click Here Demo
现在尝试一下,
关于jquery - 数据表错误: Requested unknown parameter '1' from the data source for row 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24891849/