[英]Procedural elements references in Blazor
I'm trying to make a mission display page, which display each mission summary into a row of a table, and if you click on one of the row, it expands the row which show the mission details.我正在尝试制作一个任务显示页面,它将每个任务摘要显示到表格的一行中,如果您单击其中一行,它会展开显示任务详细信息的行。
Because the number of mission isn't static, I have to use procedural logic to display all of them (it's just getting into a for
loop, nothing too spectacular.)因为任务的数量不是静态的,所以我必须使用程序逻辑来显示所有这些(它只是进入一个
for
循环,没什么特别的。)
However, because of procedural logic, I can't really make some static identifiers for my rows as it goes through a loop, and I need to know on which row I'm clicking to know what to expand.但是,由于程序逻辑的原因,当我的行通过循环时,我无法真正为我的行创建一些静态标识符,我需要知道我在哪一行上单击以了解要展开的内容。
What should I do to identify which row I'm clicking on ?我应该怎么做才能确定我点击了哪一行? I'm accepting any solutions, either with only C# or by JS Interop.
我接受任何解决方案,无论是仅使用 C# 还是使用 JS Interop。
Pass the object to the onclick
event handler将对象传递给
onclick
事件处理程序
@foreach(var item in items)
{
<tr @onclick="() => OnRowClicked(item)">
...
</tr>
}
@code {
private void OnRowClicked(Item item)
{
Expand(item);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.