【发布时间】:2018-08-25 01:42:10
【问题描述】:
我有一个通过数据表创建的表,该表由 JSON 文件提供,但我不知道如何向其中添加数据。使用 Node.js 作为后端。
这是我的代码:
<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>
</table>
<button id="btnAdd">Add</button>
<script>
$(document).ready(function () {
$('#table_id').DataTable({
"ajax" : {"url":"/personas.json", "dataSrc":"personas"},
"columns" : [
{"data" : "id"},
{"data" : "nombre"},
{"data" : "apellido"},
{"data" : "email"},
{"data" : "confirmado"}
]
});
});
$("#btnAdd").click(add);
function add(){
}
</script>
目标是让“btnAdd”弹出一个窗口,其中包含我可以填写数据的表单,然后将其添加到 JSON 文件中,并将其显示在表格上,但我不知道从哪里开始。
【问题讨论】:
标签: jquery json datatables