そのため、jQuery と一緒にデータテーブルを使用していますが、これが機能しない理由について少し困惑しています。私のHTMLは次のようになります。
<table id="surnamePrimaryPartitionTable" border=1 class="display partitionDisplay">
<caption>Partitions</caption>
<thead>
<tr style="background-color: #afeeee;">
<th>Partition</th>
<th>CPU %</th>
<th>Search Count</th>
<th>Person Count</th>
<th>Disk Space</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
いくつかのテーブルがあり、それぞれが同様の形式に従い、それぞれが partitionDisplay クラスを使用します (実際には、後で jQuery を使用してすべてのテーブルを選択できるようにするために使用するクラスです)。
そのため、データテーブルを破棄しようとすると問題が発生します。ここに私が持っているものがあります:
function DeletePartitionInformation(data) {
jQuery(".partitionDisplay").each(function(){
jQuery(this).dataTable().fnDestroy();
});
jQuery("table tbody").each(function() {
jQuery(this).html("");
})
}
このコードは、最初のテーブルでは正しく機能しているように見えますが、例外がスローされ、後続のテーブルでは機能しません。私が得ているJavaScriptエラーメッセージは次のとおりです。
キャッチされていない TypeError: 未定義のプロパティ 'asSorting' を読み取ることができません
このエラーを Google で簡単に検索すると、通常、タグ内に要素がネストされていることが原因であることがわかります。ただし、これは問題ではないようです。これを示すために、他の 3 つのテーブルのコードを投稿します。
<table id="surnamePrimarySubpartitionTable" border=1 class="display partitionDisplay">
<caption>SubPartitions</caption>
<thead>
<tr style="background-color: #afeeee;">
<th>Partition</th>
<th>SubPartition</th>
<th>CPU %</th>
<th>Search Count</th>
<th>Person Count</th>
<th>Disk Space</th>
<th>Begin</th>
<th>End</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<table id="givenNullSurnamePartitionTable" border=1 class="display partitionDisplay">
<caption>Partitions</caption>
<thead>
<tr style="background-color: #98fb98;">
<th>Partition</th>
<th>CPU %</th>
<th>Search Count</th>
<th>Person Count</th>
<th>Disk Space</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<table id="givenNullSurnameSubpartitionTable" border=1 class="display partitionDisplay">
<caption>SubPartitions</caption>
<thead>
<tr style="background-color: #98fb98;">
<th>Partition</th>
<th>SubPartition</th>
<th>CPU %</th>
<th>Search Count</th>
<th>Person Count</th>
<th>Disk Space</th>
<th>Begin</th>
<th>End</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
最後の注意: 以下のコードを使用すると、実際に必要な動作を得ることができます。ただし、要素IDをハードコーディングするのではなく、要素をループしたいので、そうしないことをお勧めします。
function DeletePartitionInformation(data) {
jQuery("#surnamePrimarySubpartitionTable").dataTable().fnDestroy();
jQuery("#surnamePrimaryPartitionTable").dataTable().fnDestroy();
jQuery("#givenNullSurnameSubpartitionTable").dataTable().fnDestroy();
jQuery("#givenNullSurnamePartitionTable").dataTable().fnDestroy();
jQuery("table tbody").each(function() {
jQuery(this).html("");
})
}