我开发了用于数据表的功能,该数据表正常工作并显示了数据,但是当我更新元素时,检查数据是否正常工作, 我必须刷新浏览器以显示正确的数据(已修改)。并且此错误(我使用Angular 5):
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'draw' of undefined
TypeError: Cannot read property 'draw' of undefined
file.ts:
async getTicketsById(noteId) {
this.notefrais = await this._somService.getNoteFraise(noteId);
this.view = this.notefrais.Tickets;
//this.btnVisible = true;
for (var i = 0; i < this.view.length; i++) {
if (this.view[i].StatutTicket == 4) {
this.btnVisible = false;
}
else {
this.btnVisible = true;
}
}
setTimeout(function () {
this.table = $('#nf-table').DataTable({
pageLength: 5,
});
}, 1000);
this.refreshTable();
}
async refreshTable() {
this.view = this.notefrais.Tickets;
// this.btnVisible = true;
for (var i = 0; i < this.view.length; i++) {
if (this.view[i].StatutTicket == 4) {
this.btnVisible = false;
}
else {
this.btnVisible = true;
}
}
$('input:checkbox[name^="option_input"]').each(function (i) {
$(this).prop('checked', false);
});
this.table.draw();
}
和file.html:
<div class="ibox-body">
<table class="table table-striped table-bordered table-hover" id="nf-table">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbode>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>