私はテーブルを持っている最初の行に適用され、私は都市としての「ラバト」を含むすべての行を削除したいが、何も起こりませんでした。しかし、私が最初の行の値を変更したとき、それは機能しました。 それはなぜ最初の行だけのために働くのですか?ここでjQueryのDataTableの削除が行</p> <p><a href="https://i.stack.imgur.com/Y3YjA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y3YjA.png" alt="enter image description here"></a></p> <p>のカップルとだけ
は私のコードです:
$("#btnSave").click(function() {
var table = $("#mainTable").DataTable({});
var nodes = [];
table.rows().every(function(rowIdx, tableLoop, rowLoop) {
if (this.data()[3] == 'Rabat')
nodes.push(this.node())
})
nodes.forEach(function(node) {
table.row(node).remove().draw()
})
});
HTMLコード:
<table id="mainTable" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>City</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tbody>
<tr>
<td>@item.id</td>
<td>@item.name</td>
<td>@item.country</td>
<td>@item.city</td>
</tr>
</tbody>
}
</table>
'this.data()[3]'が問題になります。 –
しかし、なぜそれが最初の行のために働くのですか? –
コードをデバッグすると、最初の行は正常ですが、他は定義されていません –