DataTables错误:请求的未知参数' 1'来自第0行的数据源

时间:2014-07-22 15:41:52

标签: jquery json jquery-datatables

我尝试使用JSON / DataTables创建一个表,使用JSON数据作为源。我已经验证了数据没问题。不幸的是,我不断收到此错误:" DataTables警告(表格ID ='示例'):请求的未知参数' 1'来自第0行和第34行的数据源。我不确定我在这里做错了什么:

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>

我得到的只是错误消息和表头。页脚实际显示:&#34;显示4,008个条目中的1到10个&#34;,这可能表示它正在查看数据。谢谢!

1 个答案:

答案 0 :(得分:4)

问题是"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 data to array data

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

他的演示...... Click Here Demo

现在试试吧,