我在本地创建了一个web (角5)页面主机,我使用datatable(Jquery)在html上的表中添加了一些额外的特性(如排序、过滤器、search..etc)。当我首先尝试它时,datatable如我所期望的那样工作,但是当我重新加载页面时,它的ui也会发生变化,然后所有的datatable函数都不能工作-- anymore....it似乎是随机发生的。因此,我清除所有cookie,禁用页面使用cookie,但结果仍然相同。我还尝试使用控制台日志查看$('#myTable').DataTable();在重新加载页面时是否运行,它实际上每次重新加载页面时都会运行。我不知道这是怎么回事。注意:我使用localhost/3000将我的页面重定向到\book页面。下面是我的示例索引文件代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>QnAlist</title>
<base href="/">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js"></script>
</head>
<body>
<app-root></app-root>
<script>
$(document).ready(function () {
$('#myTable').DataTable();
});
</script>
</body>
</html>下面是我的图书组件html代码:
<div class="container">
<h1 style="text-align: center">QnA List</h1>
<table class="display" id = 'myTable' >
<thead>
<tr>
<th> Question </th>
<th> Answer </th>
<th> Date </th>
</tr>
</thead>
<tbody>
<tr *ngFor="let book of books">
<td>{{ book.question }}</td>
<td>{{ book.answer }}</td>
<td>{{ book.timestamp }}</td>
</tr>
</tbody>
</table>
</div>发布于 2018-03-23 17:50:50
我想出了解决这个问题的方法.我找不到答案,所以我不再使用jquery表,而使用。正如我所期望的那样。
发布于 2021-08-24 01:12:29
我的问题是datatable名称:this.dataTable =$ ('# dtData‘)。 id dtData I在几个html组件中分配它,我的解决方案是用自己的名称命名每个组件的每个数据表: dtDataPerson、dtDataEmployee等等。
https://stackoverflow.com/questions/49072145
复制相似问题