如何解决通过Ajax初始化数据表-无数据显示
我有一个数据表,我想通过Ajax调用http:// url / api / v1 / shocks进行初始化
table.blade.php
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-striped table-md" id="table-raw-shocks" width="100%" cellspacing="0">
<thead>
<tr>
<th>Record Id</th>
<th>Count</th>
<th>Date</th>
<th>Amplitude 1 (G)</th>
<th>Amplitude 2 (G)</th>
<th>Time 1 (s)</th>
<th>Time 2 (s)</th>
<th>Freq 1 (Hz)</th>
<th>Freq 2 (Hz)</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Record Id</th>
<th>Count</th>
<th>Date</th>
<th>Amplitude 1 (G)</th>
<th>Amplitude 2 (G)</th>
<th>Time 1 (s)</th>
<th>Time 2 (s)</th>
<th>Freq 1 (Hz)</th>
<th>Freq 2 (Hz)</th>
</tr>
</tfoot>
</table>
</div>
</div>
JavaScript部分
$(document).ready(function () {
initShocksActivityTable();
});
function initShocksActivityTable() {
var url = '{{ route("api:v1:shocks.index") }}'; //http://url/api/v1/shocks
var table = $('#table-raw-shocks-all').DataTable({
responsive: true,responsive: {
details: {
type: "column",target: "tr"
}
},orderCellsTop: true,fixedHeader: true,dom: "Bfrtip",buttons: ["copy","csv","excel","pdf","print"],columnDefs: [{
sortable: true
}],"ajax": url,"columns": [{
"data": "attributes.record_id"
},{
"data": "attributes.count"
},{
"data": "attributes.date_time"
},{
"data": "attributes.amplitude_1"
},{
"data": "attributes.amplitude_2"
},{
"data": "attributes.time_1"
},{
"data": "attributes.time_2"
},{
"data": "attributes.freq_1"
},{
"data": "attributes.freq_2"
},],lengthMenu: [
[10,25,50,-1],[10,"All"]
],iDisplayLength: 10,order: [
[2,"desc"]
]
});
}
属性包含我要添加到数据表中的所有必需数据。
这样做时,我没有显示任何数据。我怀疑是因为我的数据是一个数组([0],1 ...) 我试图添加这段代码(https://datatables.net/reference/option/ajax.dataSrc)
"dataSrc": "data.attributes"
但是它仍然不起作用。
我敢肯定,这是我想念的,但是我很难找到正确提取数据的问题。
你能帮我吗?谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。