Blazor
AntDesign.TreeSelect
Demo
<SimpleTreeSelect TItem="WebMenu" @bind-Value="selectMenuId"
DataSource="@(LocalJsonData.Data)"
TitleExpression="m => m.MenuName"
KeyExpression="m => m.MenuId"
DataItemExpression="(menus, menuId) => menus.FirstOrDefault(m => m.MenuId == menuId)"
ChildrenMethodExpression="menuId => LocalJsonData.GetMenusByParentId(menuId)"
IsLeafExpression="m => LocalJsonData.HasChild(m.MenuId)"
Placeholder="Please select"
TreeDefaultExpandAll>
</SimpleTreeSelect>
select MenuId:<Input Placeholder="current Select MenuId" @bind-Value="@selectMenuId" /><Button OnClick="ChangeMenuId" OnClickStopPropagation="true">Update</Button>
@code{
private string selectMenuId = "3";
private void ChangeMenuId()
{
selectMenuId = "5";
}
}
注意点1:
如果想在绑定数据后,默认选中值,一定要有DataItemExpression,否则会出现,选中了值,但是Title不变的问题
注意点2:
如果是在自建组件中使用了TreeSelect,多次展示同一个组件,需要在OnParametersSet里进行赋予初始化值