DataTables错误:从数据源请求第0行的未知参数"1" [英] DataTables error: Requested unknown parameter '1' from the data source for row 0

查看:162
本文介绍了DataTables错误:从数据源请求第0行的未知参数"1"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSON数据作为源的jQuery/DataTables创建表.我已经验证了数据很好.不幸的是,我一直在收到此错误:"DataTables警告(表ID ='示例'):从数据源请求的第0行的未知参数'1'".我不确定在这里我做错了什么:

I'm trying to create a table using jQuery / DataTables using JSON data as a source. I have validated the data it is fine. Unfortunately I'm keep getting this error: "DataTables warning (table id='example'): Requested unknown parameter '1' from the data source for row 0". I'm not sure what am I doing wrong here:

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,008个4,008项",这可能表示它正在查看数据.谢谢!

All I get is the error message and the table header. The footer actually shows: "Showing 1 to 10 of 4,008 entries", which may indicate that it is looking at the data. Thanks!

推荐答案

问题是"aaData": dataSet,接受数组数据,但是您仍不能转换json数据,

issue is "aaData": dataSet, accecpt array data,but you are not convert json data still,

对此进行检查,

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);

这里是他的演示... 单击此处演示

Here His demo...Click Here Demo

现在尝试,

这篇关于DataTables错误:从数据源请求第0行的未知参数"1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆