【发布时间】:2020-02-15 12:53:55
【问题描述】:
型号:
public class FiltersModel
{
public CheckBoxListWithTitle Brand { get; set; }
}
public class CheckBoxListWithTitle
{
public List<FilterCheckBox> CheckBoxes { get; set; }
}
public class FilterCheckBox
{
public string Value { get; set; }
public bool Checked { get; set; }
}
剃须刀:
@foreach (var item in Model.Brand.CheckBoxes)
{
<label>
@item.Value
<input type="checkbox" @onchange="@FilterChangedBrand" />
</label>
}
@代码:
public FiltersModel Model { get; set; } // Initialized in OnParametersSet
private void FilterChangedBrand(UIChangeEventArgs e)
{
string newCheckedBrand = e.Value.ToString();
// Now How to Find and Set the relevant Model property to newCheckedBrand
FiltersChanged?.Invoke(Model);
}
如何在 FilterChangedBrand 方法中查找相关的 Model 属性并将其设置为 newCheckedBrand。
或者在复选框标记中使用@bind="@item.Checked",然后在其中一个复选框的选中状态发生变化时引发事件?
【问题讨论】: