【发布时间】:2013-11-06 11:31:10
【问题描述】:
我正在使用 jquery DataTables 将我的 JSON 数据绑定到表,但是当我将 JSON 对象指定到 DataTable 的“aaData”选项时,它会抛出这个错误:
“DataTables 警告(表 id = 'tblReceipt'):从第 0 行的数据源请求未知参数 '1'”
我的 JSON 对象如下所示:
var r = [
{ "Vid": "1", "Receiptno": "AFL123", "Type": "3", "Branch": "AFL", "Date": "23/11/2013" },
{ "Vid": "2", "Receiptno": "AFL124", "Type": "4", "Branch": "AFL", "Date": "24/11/2013" },
{ "Vid": "3", "Receiptno": "AFL125", "Type": "6", "Branch": "AFL", "Date": "25/11/2013" },
];
我像这样将它传递给 DataTables:
$("#tblReceipt").dataTable({
"aaData": JSON.stringify(r),
"bJQueryUI": true,
"bDestroy": true,
"iDisplayLength": 50,
"bProcessing": true,
"aaSorting": [[0, 'desc']],
"aoColumns": [
{ "mData": "Vid" },
{ "mData": "Receiptno" },
{ "mData": "Type" },
{ "mData": "Branch" },
{ "mData": "Date" },
],
"oLanguage": {
"sProcessing": "Fetching Data, Please wait..."
},
});
任何帮助将不胜感激!
【问题讨论】:
-
你为什么要为
aaData进行字符串化?aaData是字符串吗? -
尝试删除最后一个逗号。
-
请将答案标记为已接受,因为我发布了一个工作演示,证明问题已解决
标签: javascript asp.net jquery-datatables