【发布时间】:2021-05-25 15:56:50
【问题描述】:
所以,我正在使用 blazor 来制作应用程序。在剃须刀页面的 HTML 部分,我正在制作这样的表格:
@for (int index = 1; index < amounts.Count; index++)
{
<table>
<tr>
<td> @amounts[index] </td>
</tr>
</table>
}
我需要为每个单元格添加一个@onclick 事件,问题是该函数的 de 参数随着 for 循环而变化。
这意味着如果我这样做(见下文)。每个单元格都会做onclick(amounts.Count)(即表的最后一个索引,索引的最后一个值)。
@for (int index = 1; index < amounts.Count; index++)
{
<table>
<tr>
<td @onclick="()=>Redirect(index)"> @amounts[index] </td>
<tr>
</table>
}
我不确定我是否解释得足够充分,我的问题是否清楚。如果不是,请告诉我。
一种解决方案可能是我获取单元格的行号。我已经尝试了一些方法,但是如果您使用 for 函数制作这样的表格,我无法弄清楚如何获取行号。
【问题讨论】: