我正在使用数据表,并且已成功设置页面上除一个表外的所有表。这是在页面上进行设置的脚本:
leadRemindersDatatable = $('#leadRemindersDatatable').DataTable({
dom: "<?php echo ($dont_show_new_reminder_btn) ? 'Bfrtip' : "B < 'toolbar' > frtip " ; ?>",
"language": {
"lengthMenu": '_MENU_ ',
"search": '',
"searchPlaceholder": "<?php echo __('form.search') ; ?>"
},
responsive: true,
processing: true,
serverSide: true,
pageLength: 25,
ordering: false,
"ajax": {
"url": '<?php echo route("datatables_reminders"); ?>',
"type": "POST",
'headers': {
'X-CSRF-TOKEN': '<?php echo csrf_token() ; ?>'
},
"data": function (d) {
d.remindable_type = "<?php echo $remindable_type; ; ?>";
d.remindable_id = "<?php echo $remindable_id; ; ?>";
}
}
});
这是后端返回的响应JSON:
{
"draw": 1,
"recordsTotal": 1,
"recordsFiltered": 1,
"data": [
[
"Don't forget this!",
"2019-09-06",
" <a class=\"\" href=\"http:\/\/192.168.1.152\/users\/profile\/1\">Matthew Prythero<\/a>",
"No",
"<a class=\"edit_item btn btn-light btn-sm\" data-id=\"1\" href=\"#\"><i class=\"far fa-edit\"><\/i><\/a> <a class=\"delete_item btn btn-danger btn-sm\" href=\"http:\/\/192.168.1.152\/reminders\/remove\/1\"><i class=\"far fa-trash-alt\"><\/i><\/a>"
]
]
}
如您所见,返回的响应永远不会超过第四个索引。但是我不知道为什么它会继续前进,并尝试从未知的第5个索引创建表格单元。
这是我在html中的表格的基本html:
<table class="table table-striped table-bordered" cellspacing="0" width="100%" id="leadRemindersDatatable">
<thead>
<tr>
<th><?php echo __("form.description");?></th>
<th><?php echo __("form.date");?></th>
<th><?php echo __("form.remind");?></th>
<th><?php echo __("form.is_notified");?></th>
<th><?php echo __("form.action");?></th>
</tr>
</thead>
</table>