@@ -151,13 +151,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
151
151
/// </summary>
152
152
/// <remarks>通过设置 <see cref="ShowSearch"/> 开启</remarks>
153
153
[ Parameter ]
154
- public Func < string ? , Task > ? OnSearchAsync { get ; set ; }
155
-
156
- /// <summary>
157
- /// 获得/设置 页面刷新是否重置已加载数据 默认 false
158
- /// </summary>
159
- [ Parameter ]
160
- public bool IsReset { get ; set ; }
154
+ public Func < string ? , Task < List < TreeViewItem < TItem > > ? > > ? OnSearchAsync { get ; set ; }
161
155
162
156
/// <summary>
163
157
/// 获得/设置 带层次数据集合
@@ -345,11 +339,6 @@ protected override void OnParametersSet()
345
339
SearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewSearchIcon ) ;
346
340
ClearSearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewResetSearchIcon ) ;
347
341
LoadingIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewLoadingIcon ) ;
348
-
349
- if ( IsReset )
350
- {
351
- _rows = null ;
352
- }
353
342
}
354
343
355
344
/// <summary>
@@ -358,35 +347,32 @@ protected override void OnParametersSet()
358
347
/// <returns></returns>
359
348
protected override async Task OnParametersSetAsync ( )
360
349
{
361
- if ( Items == null )
362
- {
363
- // 未提供数据显示 loading
364
- return ;
365
- }
366
-
367
- if ( Items . Count > 0 )
350
+ if ( Items != null )
368
351
{
369
- await CheckExpand ( Items ) ;
370
- }
352
+ if ( Items . Count > 0 )
353
+ {
354
+ await CheckExpand ( Items ) ;
355
+ }
371
356
372
- if ( ShowCheckbox && ( AutoCheckParent || AutoCheckChildren ) )
373
- {
374
- // 开启 Checkbox 功能时初始化选中节点
375
- TreeNodeStateCache . IsChecked ( Items ) ;
376
- }
357
+ if ( ShowCheckbox && ( AutoCheckParent || AutoCheckChildren ) )
358
+ {
359
+ // 开启 Checkbox 功能时初始化选中节点
360
+ TreeNodeStateCache . IsChecked ( Items ) ;
361
+ }
377
362
378
- // 从数据源中恢复当前 active 节点
379
- if ( _activeItem != null )
380
- {
381
- _activeItem = TreeNodeStateCache . Find ( Items , _activeItem . Value , out _ ) ;
382
- }
363
+ // 从数据源中恢复当前 active 节点
364
+ if ( _activeItem != null )
365
+ {
366
+ _activeItem = TreeNodeStateCache . Find ( Items , _activeItem . Value , out _ ) ;
367
+ }
383
368
384
- if ( _init == false )
385
- {
386
- // 设置 ActiveItem 默认值
387
- _activeItem ??= Items . FirstOrDefaultActiveItem ( ) ;
388
- _activeItem ? . SetParentExpand < TreeViewItem < TItem > , TItem > ( true ) ;
389
- _init = true ;
369
+ if ( _init == false )
370
+ {
371
+ // 设置 ActiveItem 默认值
372
+ _activeItem ??= Items . FirstOrDefaultActiveItem ( ) ;
373
+ _activeItem ? . SetParentExpand < TreeViewItem < TItem > , TItem > ( true ) ;
374
+ _init = true ;
375
+ }
390
376
}
391
377
}
392
378
@@ -609,21 +595,25 @@ private async Task OnEnterAsync(string? searchText)
609
595
610
596
private Task OnEscAsync ( string ? searchText ) => OnClickResetSearch ( ) ;
611
597
598
+ private List < TreeViewItem < TItem > > ? _searchItems ;
599
+
612
600
private async Task OnClickSearch ( )
613
601
{
614
602
if ( OnSearchAsync != null )
615
603
{
616
- await OnSearchAsync ( _searchText ) ;
604
+ _searchItems = await OnSearchAsync ( _searchText ) ;
605
+ _rows = null ;
606
+ StateHasChanged ( ) ;
617
607
}
618
608
}
619
609
620
- private async Task OnClickResetSearch ( )
610
+ private Task OnClickResetSearch ( )
621
611
{
622
612
_searchText = null ;
623
- if ( OnSearchAsync ! = null )
624
- {
625
- await OnSearchAsync ( _searchText ) ;
626
- }
613
+ _searchItems = null ;
614
+ _rows = null ;
615
+ StateHasChanged ( ) ;
616
+ return Task . CompletedTask ;
627
617
}
628
618
629
619
/// <summary>
@@ -862,11 +852,13 @@ private List<TreeViewItem<TItem>> Rows
862
852
get
863
853
{
864
854
// 扁平化数据集合
865
- _rows ??= Items . ToFlat < TItem > ( ) . ToList ( ) ;
855
+ _rows ??= GetItems ( ) . ToFlat < TItem > ( ) ;
866
856
return _rows ;
867
857
}
868
858
}
869
859
860
+ private List < TreeViewItem < TItem > > GetItems ( ) => _searchItems ?? Items ;
861
+
870
862
private static string ? GetTreeRowStyle ( TreeViewItem < TItem > item )
871
863
{
872
864
var level = 0 ;
0 commit comments