我在 blazor 中有一个 html 表,它填充循环列表(减少列以显示相关代码)
@foreach (var line in lines)
{@{ var linenumber = lines.IndexOf(line)}
<td>
<DDItems @bind-Binder="line.item"></DDItems>
</td>
<td>
<button type="button" @onclick="@(() => removeRow(linenumber))">Remove</button>
</td>
}
@Code{
private List<TransactionSALine> lines = new List<TransactionSALine>();
private async Task removeRow(int linenumber)
{
lines = lines.Where(u => lines.IndexOf(u) != linenumber).ToList());
}
}
Run Code Online (Sandbox Code Playgroud)
当我从表中删除一行时,其他行中选择的项目会发生更改。
在删除带有产品“铅笔”的行之前:
取下产品“铅笔”后: