javascript - 在 JQuery 选项卡中动态加载数据表
问题描述
我计划在我的一个项目中使用 JQuery Datatables,所以我决定做一个 POC 以确保一切都按计划进行。
我建立了一个表,我将在其中打印我的对象中的值,这些值将在我的进一步开发过程中作为 JSON 接收。但是我收到了我要打印数据的 id 的 AJAX 错误。
我已经在JSFiddle上上传了代码!
HTML
<div id="tab-customers">
<table id="customers-table" class="display general-table" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone</th>
<th>Gender</th>
<th>City</th>
<th>Country</th>
</tr>
</thead>
</table>
</div>
jQuery
$(".tabs").click(function() {
var source = $(this).data("source");
var tableId = $(this).data("table");
initiateTable(tableId, source);
});
function initiateTable(tableId, source) {
var table = $("#" + tableId).DataTable({
"ajax": source,
order: [],
columnDefs: [{
orderable: false,
targets: [0]
}],
"destroy": true,
"bFilter": true,
"bLengthChange": false,
"bPaginate": false
});
}
initiateTable("customers-table", "customers");
$("#dynamic-tabs").tabs();
});
解决方案
推荐阅读
- bash - bash中的嵌套括号是什么意思?
- php - 未分配给数组的值
- android - 如何将值保存在编辑文本框中
- flutter - Flutter:按下按钮时只能在初始化程序中访问静态成员
- mongodb - 需要在mongodb中查找动态多个嵌套集合的查询
- android - 未解决的类:主要活动
- android - 使用 Volley 在 kotlin 中创建 Reqeust 类
- javascript - 使用 Node.js 启动带有参数的浏览器窗口
- sql-server - “一个 SQL server Express 2008 实例是 sqlserver.exe 可执行文件的副本”是什么意思?
- sql - 不确定为什么会出现 ORA-00918 列定义不明确