Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “数据表警告”;未知参数0“;_Javascript_Jquery_Json_Datatable_Jquery Datatables - Fatal编程技术网

Javascript “数据表警告”;未知参数0“;

Javascript “数据表警告”;未知参数0“;,javascript,jquery,json,datatable,jquery-datatables,Javascript,Jquery,Json,Datatable,Jquery Datatables,我试图使用datatables,其中包含一定数量的列和从jQueryAjax获得的对象数组 我得到一个错误: datatables warning (table id = myId requested unknown parameter 0 from the data source for row 0 搜索互联网表明,我的message_json数组中可能有不同数量的列标题和列数据 我在数据表初始化中设置了21列: var construct_messages_table = function

我试图使用datatables,其中包含一定数量的列和从jQueryAjax获得的对象数组

我得到一个错误:

datatables warning (table id = myId requested unknown parameter 0 from the data source for row 0
搜索互联网表明,我的
message_json
数组中可能有不同数量的列标题和列数据

我在数据表初始化中设置了21列:

var construct_messages_table = function(message_json){

    var oTable = $('#tableId').dataTable( {
    "sPaginationType": "full_numbers",
    "bProcessing": true,
    "bDeferRender": true,
    "aaData": message_json,
    "aoColumns": [
        { "sTitle": "coloumn1"},
        { "sTitle": "coloumn2"},
        { "sTitle": "coloumn3"},
        { "sTitle": "coloumn4"},
        { "sTitle": "coloumn5"},
        { "sTitle": "coloumn6"},
        { "sTitle": "coloumn7"},
        { "sTitle": "coloumn8"},
        { "sTitle": "coloumn9"},
        { "sTitle": "coloumn10"},
        { "sTitle": "coloumn11"},
        { "sTitle": "coloumn12"},
        { "sTitle": "coloumn13"},
        { "sTitle": "coloumn14"},
        { "sTitle": "coloumn15"},
        { "sTitle": "coloumn16"},
        { "sTitle": "coloumn17"},
        { "sTitle": "coloumn18"},
        { "sTitle": "coloumn19"},
        { "sTitle": "coloumn20"},
        { "sTitle": "coloumn21"}

    ]
} );   

};


当然还有更多的元素。而不仅仅是复制品

元素的数量必须与列的数量相同,否则
Datatables
将查找数据中未包含的值

如果要使用类似中的结构,请执行以下操作:

    [
{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"},   

{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"}];

这将告诉datatables在哪里可以找到该列的值。

Colum11上缺少的逗号是一个输入错误?@EduardoQuintana是的,从我更改实际列名时开始。我会在问题中纠正它。哦,你能提供aaData吗?@EduardoQuintana补充道。你提供的aaData有20个对象属性,但你在问题中提到object.keys显示的长度是21?
    for (var i = 0; i < message_json.length; i++){

        for (var o in message_json[i]){

           if (message_json[i][o] == null){
               message_json[i][o] = "";
           }

        }

    }
    [
{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"},   

{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"}];
    [
{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"},   

{type: "int",
id: "111",
name: "co",
description: "",
is_bool: "0",
keyword: "<tag name=&quot;various-xml&quot;>fields</xml>",
message: "hello",
temp: "world",
settings: "",
priority: "100",
enabled: "0",
secure: "1",
var1: "post",
var1_desc: "some desc↵",
var1_query: "<DATA>blah</DATA>",
prop: "1",
prop_name: "Draft",
transaction: "1",
users: "0",
table_name: "abc"}];
var oTable = $('#tableId').dataTable( {
    "sPaginationType": "full_numbers",
    "bProcessing": true,
    "bDeferRender": true,
    "aaData": message_json,
    "aoColumns": [
        { "sTitle": "coloumn1","mData":"type"},
        { "sTitle": "coloumn2","mData":"id"},
        { "sTitle": "coloumn3","mData":"name"},
        { "sTitle": "coloumn4","mData":"description"},
        { "sTitle": "coloumn5","mData":"is_bool"},...