【发布时间】:2022-02-13 19:13:55
【问题描述】:
在动态内容表中设置正文时遇到问题。
我得到表格中没有数据。
其实tad已经设置正确了,但是很可能问题出在tbody上;列的标题完美显示,但内容却没有。
谁能帮帮我?
var allart = JSON.parse(this.responseText);
console.log(allart);
var tbdy = document.createElement('tbody');
allart.Items.forEach(function (item) {
let child = document.createElement("tr");
child.innerHTML = `
<td>${item.id}</td>
<td>${item.titolo}</td>
<td>${item.marca}</td>
<td>${item.immagine}</td>
<td>${item.sezione}</td>
<td>${item.data}</td>
`;
table.appendChild(child);
})
tbdy.appendChild(tr);
table.appendChild(tbdy);
$(document).ready(function () {
$('#my-table').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [5, 10, 20, 50, 100, 200, 500],
});
$('.dataTables_length').addClass('bs-select');
});
<table id="my-table" class="row-border hover" width="90%">
<thead>
<tr>
<th class="th-sm">Id</th>
<th class="th-sm">Titolo</th>
<th class="th-sm">Marca</th>
<th class="th-sm">Immagine</th>
<th class="th-sm">Sezione</th>
<th class="th-sm">Data</th>
</tr>
</thead>
</table>
allart 是:
0: {title: 'Moto Guzzi V100 Mandello, the queen of EICMA 2021', date: '27 / 11/2021 ', brand:' Guzzi ', section:' In evidence ', id:' 123456 ',…}
1: {title: "Bimota: an adventure based on Tesi will arrive", date: '04 / 12/2021 ', brand:' Bimota ', section:' In evidence ', id:' 135623 ',…}
2: {title: "Chaleco López inaugurates' his' museum", date: '22 / 01/2022 ', brand:' Chaleco ', section:' On the front page ', id:' 256346 ',…}
【问题讨论】:
标签: javascript html