jquery - 数据表错误: Requested unknown parameter '1' from the data source for row 0

标签 jquery json datatables

我正在尝试使用 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/

相关文章:

jQuery DataTable - 动态初始化后隐藏/显示启用/禁用列过滤

javascript - jQuery/Javascript 如果宽度问题

jquery - 使用 jQuery 和 LINQ-to-Entities 在 ASP.NET MVC 客户端 View 中对 jqGrid 进行排序

javascript - jQuery 单击不是在 SVG <g> 上触发,而是在子元素上触发

javascript - 数组数组转换为对象数组

java - SelectionKey iterator.remove() 抛出 UnsupportedOperationException 和无限循环

c# - 带有 jQ​​uery DatePicker 的 ASP.NET

javascript - AJAX 将 JSON 作为字符串传递给 Controller ​​返回 Null

php - 更改显示条目期间数据表卡住

javascript - R Shiny 在带有侧面板/条件面板的选项卡之间构建链接