【发布时间】:2019-01-30 23:50:08
【问题描述】:
我正在尝试使用 DataTables 使用 JSON 文件填充表格,但每次加载页面时,表格只显示“表格中没有可用数据”。
这是我当前的代码:
<table id="table_id" class="display">
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Mail</th>
<th>Confirmado</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function () {
$('#table_id').DataTable({
"ajax" : {"url":"/personas.json", "dataSrc":""},
"columns" : [
{personas : "id"},
{personas : "nombre"},
{personas : "apellido"},
{personas : "email"},
{personas : "confirmado"}
]
});
});
</script>
这是一段 JSON 代码:
{
"personas": [
{
"id": 0,
"nombre": "Aurelia",
"apellido": "Osborn",
"email": "aureliaosborn@lovepad.com",
"confirmado": false
},
{
"id": 1,
"nombre": "Curry",
"apellido": "Jefferson",
"email": "curryjefferson@lovepad.com",
"confirmado": true
}
]
}
这是我在加载页面(部分)时得到的:
为了以防万一这可能是问题,这是 JSON 的目录:
【问题讨论】:
标签: jquery node.js ajax express