Skip to content

Commit 8d252d0

Browse files
committed
feat: 增加选中节点逻辑
1 parent 0a22a04 commit 8d252d0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/BootstrapBlazor/Components/Select/SelectTree.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<span class="@AppendClassName"><i class="@DropdownIcon"></i></span>
2121
</div>
2222
<div class="dropdown-menu">
23-
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon"
23+
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon" @ref="_tv"
2424
OnTreeItemClick="OnItemClick" ModelEqualityComparer="@ModelEqualityComparer"
2525
ShowSearch="ShowSearch" ShowResetSearchButton="ShowResetSearchButton"
2626
CanExpandWhenDisabled="CanExpandWhenDisabled"

src/BootstrapBlazor/Components/Select/SelectTree.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
166166
private TreeViewItem<TValue>? _selectedItem;
167167
private List<TreeViewItem<TValue>>? _itemCache;
168168
private List<TreeViewItem<TValue>>? _expandedItemsCache;
169+
private TreeView<TValue> _tv = default!;
169170

170171
private string? SelectTreeCustomClassString => CssBuilder.Default(CustomClassString)
171172
.AddClass("select-tree", IsPopover)
@@ -233,6 +234,12 @@ private void OnChange(ChangeEventArgs args)
233234
if (args.Value is string v)
234235
{
235236
CurrentValueAsString = v;
237+
238+
// 选中节点更改为当前值
239+
if(_tv != null)
240+
{
241+
_tv.SetActiveItem(Value);
242+
}
236243
}
237244
}
238245

0 commit comments

Comments
 (0)