【发布时间】:2017-10-02 15:51:19
【问题描述】:
我一直在尝试在 jQuery DataTables 组件中获取我的 JSON 数据。
首先我编写了 JavaScript 代码以及如下代码所示的视图:
$(document).ready(function () {
$('#myData').DataTable({
lengthChange: false,
ajax: {
url: "http://amp-local/api/wipbin/FetchChild/",
// dataSrc: 'allk'
},
columns: [
{ data: "name" },
{ data: "numbers" }
],
select: true
});
});
我的看法:
<table id="myData" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Numbers</th>
</tr>
</thead>
</table>
我的 JSON:
[{
"numbers": "38",
"name": "Bllaca"
}, {
"numbers": "28",
"name": "Kaess"
}, {
"numbers": "27",
"name": "droessmer"
}, {
"numbers": "24",
"name": "friedricha"
}]
结果是这个错误:
TypeError: undefined is not an object (evaluating 'f.length')
我的桌子是空的。
【问题讨论】:
-
您的 JSON 无效。
-
应该怎么样?
-
你最后错过了
}] -
啊,因为我只显示了我的 json 的一部分
-
好吧,无论如何添加
}]... 可以限制它,但它至少在您的示例中必须是有效的。
标签: javascript json datatable