【发布时间】:2015-07-16 08:18:37
【问题描述】:
我正在尝试从 JSON 构建一个表,但它没有正确加载数据。我想在表格中进行分页。我尝试遵循 SB Admin Bootstrap 中的格式,但无法加载任何数据。
我的 HTML 代码是:--
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="agents">
<thead>
<tr>
<th> employeeNumber</th>
<th> fullName</th>
<th>employeeEmail</th>
<th>jobTitle</th>
<th>deptNo</th>
<th>deptName</th>
<th>managerEmail</th>
<th>managerId</th>
<th>managerName</th>
<th>assignmentLastModifiedBy</th>
<th>assignmentLastModifiedDate</th>
<th>country</th>
<th>theatre</th>
<th>paymentAnalyst</th>
<th>commDateFrom</th>
</tr>
</thead>
</table>
</div>
我的脚本是:--
<script>
$(document).ready(function() {
$('#agents').dataTable( {
"ajax": 'http://localhost:8080/TestQuartz/json/agent.json'
} );
} );
</script>
我的 JSON 文件是:--
{"agent":[
{"country":"AUS","employeeNumber":"397142","assignmentLastModifiedBy":null,"assignmentLastModifiedDate":null,"paymentAnalyst":"Khoo, T","fullName":"ABC","theatre":"ASIA","managerId":"249058","commDateFrom":"2015-06-15 00:00:00.0","deptName":"Global Virtual Sales - ","managerName":"Turner, J","jobTitle":"VIRTUAL SALES ACCOUNT ","managerEmail":"ert","deptNo":"115331063","employeeEmail":"bre"},
{"country":"DEU","employeeNumber":"196091","assignmentLastModifiedBy":null,"assignmentLastModifiedDate":null,"paymentAnalyst":"Hatlak, T","fullName":"Gros, S","theatre":"EURO","managerId":"52367","commDateFrom":"2006-11-01 00:00:00.0","deptName":"Global Virtual Sales - Germany HQ","managerName":"Mer, W","jobTitle":"TERRITORY BUSINESS MANAGER.III.SALES.XYZ","managerEmail":"wme","deptNo":"515031281","employeeEmail":"sim"},
{"country":"FIN","employeeNumber":"598401","assignmentLastModifiedBy":null,"assignmentLastModifiedDate":null,"paymentAnalyst":"Hatlak, T","fullName":"Kur, Es","theatre":"EURO","managerId":"144218","commDateFrom":"2011-10-01 00:00:00.0","deptName":"EU SS Geo Finland OTHER","managerName":"Lunt, Tha","jobTitle":"CLIENT SERVICES MANAGER.II.SERVICE SALES.XYZ","managerEmail":"tlu","deptNo":"561038082","employeeEmail":"eku"},
{"country":"USA","employeeNumber":"399411","assignmentLastModifiedBy":null,"assignmentLastModifiedDate":null,"paymentAnalyst":"Spaulding, S,"fullName":"Hen, Cr Jo","theatre":"US","managerId":"153592","commDateFrom":"2015-06-22 00:00:00.0","deptName":"Michigan Select","managerName":"Wil, Sc A","jobTitle":"SYSTEMS ENGINEER-C.II.SALES.XYZ","managerEmail":"sco","deptNo":"020230434","employeeEmail":"cra"}
]}
谁能帮帮我?
问候。
【问题讨论】:
-
你不需要 tbody 元素吗?
-
理想情况下,引导程序会根据脚本自动加载 tbody。
-
尝试将 json 文件中的
agent更改为data,或在 AJAX 请求中添加'dataSrc': 'agent'参数 -
正如@vogomatix 所说,您需要将
<tbody>标记为空才能填充数据表 -
用 sAjaxSource 改变 ajax。您使用的是哪个版本的数据表
标签: javascript json html datatables bootstrapping