数据表错误:从数据源请求未知参数“1”,0行(DataTables error: Requested

2019-10-20 12:45发布

我试图创建一个使用使用JSON数据源的jQuery /数据表的表。 我已经验证了这是很好的数据。 不幸的是,我不断收到此错误:“数据表警告(表ID =‘示例’):请求的未知参数‘1’从0行的数据源”。 我不知道我在做什么错在这里:

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>

我得到的是错误信息和表头。 页脚竟表示:“显示1到4,008 10项”,这可能表明,它正在看的数据。 谢谢!

Answer 1:

问题是"aaData": dataSet, accecpt阵列数据,但你是不是还在转换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 data to array data

var dataSet=[];
    $.each(o,function(i,k){
          dataSet.push( $.map(o[i], function(el) { return el; }));
    });
console.log(dataSet);

他在这里的演示... 点击这里演示

现在就试试,



文章来源: DataTables error: Requested unknown parameter '1' from the data source for row 0