【发布时间】:2016-06-29 08:34:07
【问题描述】:
DataTables Cannot read property 'length' of undefined
我有与上面链接相同的问题。我有一个指向 json 数据的链接。
我的查询:
$('#card-table').DataTable({
"ajax": "http://project-maria-1350.appspot.com/getPeople?key=CX1231466035200"
});
我的 HTML 代码:
`<div id="passenger" class="tab-pane fade in active">
<table id="card-table" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Gender</th>
<th>Nationality</th>
<th>Age</th>
<th>Class</th>
<th>Boarding No.</th>
<th>Seat No.</th>
<th>Group Code</th>
</tr>
</thead>
</table>
</div>`
我收到Uncaught TypeError: Cannot read property 'length' of undefined.数据显示。但是排序不起作用。
请帮助我。谢谢。
【问题讨论】:
-
您来自后端的列数是否与 HTML 中指定的相同?请检查它,因为大多数时候这会导致未定义的长度问题。
-
您是否在根据任何特定字段进行排序时收到此错误?根据你的代码和数据检查这个 plunker plnkr.co/edit/9ug2unk2kc4NuGLbvW2v?p=preview ,我没有看到任何问题。
-
不,这根本不是同一个问题。首先你的数据不是 JSON,它是一个字符串数组;此外,您的服务器脚本没有
Access-Control-Allow-Origin,因此在基于浏览器的数据表上下文中无用。
标签: javascript jquery datatable