问题描述
参考此post,我试图动态添加组件。我可以渲染这些,但是我所需要的只是以动态的方式影响那些组件的属性值。就我而言,我正在验证每个输入,并在发生模糊事件时向这些输入相应地添加类。
我知道我可以通过影响绑定到class属性的变量来实现。但是我不知道如何获取特定元素来更改模糊处理程序中的类。
这是我尝试过的。
<ul>
@for (int i = 0; i < userNames.Count; i++)
{
int j = i; // copy i to be safe
<li>
<input type="text" class="@userNames[j]" @onblur="onblur" />
</li>
}
</ul>
<button @onclick="AddUser">Add User</button>
@*to verify the binding*@
@foreach (int userName in userNames)
{
<p>@userName</p>
}
@code
{
List<int> userNames = new List<int>() { 0 };
public int count = 0;
void AddUser()
{
count++;
userNames.Add(count);
}
public void onblur(Microsoft.AspNetCore.Components.Web.FocusEventArgs args)
{
// Here I want to validate the correspoding input based on value and update the class property of the respective element.
}
}
我也想使用RenderFragment尝试相同的操作。
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)