Jquery DataTables.net:未能将负int放入表

时间:2015-11-13 20:27:28

标签: jquery datatables

我有一个API,可以返回Id字段的一些负数。这是我的数据表脚本:

$(document).ready(function () {
            $('#myTable').DataTable( {
                ajax: {
                    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")',
                    "columns": [
                        { "type" : "num", "data": "Id"},
                        { "data": "Name" },
                        { "data": "Alias" },
                        { "data": "DateQuery" },
                        { "type" : "num", "data": "Condition" },
                        { "type" : "num", "data": "TimeSecLastCondition" }
                    ]
                }

            } );
        });

从ajax查询返回JSON:

{
    "data": [{
        "Id": -2144725655,
        "Name": "NodeName",
        "Alias": "NodeAlias",
        "DateQuery": "2015-11-13T08:16:04",
        "Condition": 0,
        "TimeSecLastCondition": 1558
    }]
}

错误:

  

"请求未知参数' 0'对于第0行,第0列。"

1 个答案:

答案 0 :(得分:3)

您正在混合使用ajax选项和其他选项。而不是

ajax: {
    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")',
    "columns": [
        { "type" : "num", "data": "Id"},
        { "data": "Name" },
        { "data": "Alias" },
        { "data": "DateQuery" },
        { "type" : "num", "data": "Condition" },
        { "type" : "num", "data": "TimeSecLastCondition" }
    ]
})

你应该做

ajax: {
    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")'
},
columns: [
     { "type" : "num", "data": "Id"},
     { "data": "Name" },
     { "data": "Alias" },
     { "data": "DateQuery" },
     { "type" : "num", "data": "Condition" },
     { "type" : "num", "data": "TimeSecLastCondition" }
  ]
}