我在我的应用程序中使用 jquery 数据表,插件链接 https://datatables.net/
我想用 JSON 填充我的数据表,但失败了。这是我的代码。
HTML:
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Code</th>
<th>Description</th>
<th>isActive</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
<th>Name</th>
<th>Code</th>
<th>Description</th>
<th>isActive</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
JS:
$(document).ready(function() {
console.log("hi ready");
$('#example').DataTable({
retrieve: true,
ajax: {
url: '/ProductLicensingApplication/feature/list',
dataSrc: ''
},
"columns": [
{ "data": "id" },
{ "data": "name" },
{ "data": "code" },
{ "data": "description" },
{ "data": "isActive" }
]
});
} );
但我无法将数据填充到表格中,因为表格显示表格中没有可用的数据..您可以在图片中看到
最佳答案
如 documentation 中所写。 ajax.dataSrc
选项用于告诉 DataTables 数据数组在 JSON 结构中的位置。空字符串是一种特殊情况,它告诉 DataTables 需要一个数组。
在您的情况下,JSON 是一个对象,您应该设置 dataSrc : 'features'
关于javascript - 如何使用 json 填充 jquery 数据表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43536002/