javascript - 如何将 DataTable 与对象数组一起使用?
问题描述
我正在尝试使用属性“数据”在表格中显示我的数据,但表格不起作用。我使用本地字符串数组进行了测试并且效果很好,我不知道为什么使用对象表不起作用
ngAfterViewInit() {
this.listarNotificacao()
$('#datatables').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
lengthChange: false,
responsive: true,
searching: true,
data: this.notificacoes,
columns: [{
data: 'guidNotificacao'
},
{
data: 'titulo'
},
{
data: 'descricao'
},
{
data: 'escopo'
},
],
language: {
search: "_INPUT_",
searchPlaceholder: "Pesquisar promoções",
},
}
});
const table = $('#datatables').DataTable();
$('#inputSearch').on('keyup', function() {
table.search(this.value).draw();
});
}
<div class="material-datatables">
<table id="datatables" class="table table-no-bordered " cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>#</th>
<th>Título</th>
<th>Descrição</th>
<th>Escopo</th>
</tr>
</thead>
</table>
</div>
解决方案
您的数据表初始化中有错字。语言后面有一个额外的大括号。如果您查看浏览器的开发控制台,它会告诉您这一点。
推荐阅读
- c# - 如何使其从文本文件中读取c#
- elixir - Flow中的并行处理不是并行的吗?
- amazon-web-services - 如何编写 yml 文件将烧瓶应用程序从 github 上传到 aws ec2 windows 实例上的 iis 服务器?
- c - C中的错误:“一元'*'的无效类型参数(具有'int')”,“来自不兼容的指针类型的赋值”
- sql - 一列中的组合超过另一列的分区 - BigQuery
- graphql - 盖茨比内容丰富的嵌入图像
- azure-iot-hub - 通过 REST API 在 azure DPS 中更新个人注册证书
- python - 嵌套 for 和 if 在列表推导中
- bash - 使用 bash 在远程服务器上执行多个命令
- javascript - 存储 dialogflow api 的代理 SessionsClient