我有一个带有约60个复选框的表单,我必须根据从数据库中获取的用户个人资料来随机激活一些复选框。我有要选择的复选框的ID。 Blazor有什么办法做到这一点?
第一个元素是select,我可以在其中选择某个用户角色,为此我会收到必须针对该特定角色激活的复选框ID的列表
<select class="form-control" @bind:event="onInput" @bind="@D5UserTitle" @onchange="PopulateaccessRights">
<option selected disabled>Please select role...</option>
@foreach (var title in Titles) {
<option value="@title.PkId">@title.Jobtitle1</option>
}
</select>
<input type="checkbox" id="sma" />
<input type="checkbox" id="smb" />
<input type="checkbox" id="smc" />
<input type="checkbox" id="smd" />
@code{
protected override async Task OnInitializedAsync()
{
D5Users = await us.GetUsersAsync();
Titles = await us.GetJobTitlesAsync();
ADUsers = await us.GetaDUsersAsync();
}
private void PopulateaccessRights()
{
// Here we acquire a list of the IDs of every checkbox to tick for that specific role. The result looks like this: sma;smd;CM_A;CESAR_A;MBKSO_A;OTB_A;VPLUS_A;MW_A;OD_A;XP_A
Every corresponding checkbox must be ticked.
List<string> ConfigurationString = Titles.Where(s => s.PkId == 25).First().ConfigurationString.Split(";").ToList();
// Here's where I'd like to activate the checkboxes
}
}