File tree Expand file tree Collapse file tree 3 files changed +10
-39
lines changed
BootstrapBlazor.Server/Components/Samples
BootstrapBlazor/Components/TreeView Expand file tree Collapse file tree 3 files changed +10
-39
lines changed Original file line number Diff line number Diff line change 173173<DemoBlock Title =" @Localizer[" TreeViewShowSearchTitle " ]"
174174 Introduction =" @Localizer[" TreeViewShowSearchIntro " ]"
175175 Name =" ShowSearch" >
176- <TreeView TItem =" TreeFoo" Items =" @SearchItems1" ShowSearch =" true" OnSearchAsync =" @OnSearch1Async " ></TreeView >
176+ <TreeView TItem =" TreeFoo" Items =" @SearchItems1" ShowSearch =" true" OnSearchAsync =" @OnSearchAsync " ></TreeView >
177177</DemoBlock >
178178
179179<DemoBlock Title =" @Localizer[" TreeViewFixedSearchTitle " ]"
180180 Introduction =" @Localizer[" TreeViewFixedSearchIntro " ]"
181181 Name =" IsFixedSearch" >
182- <TreeView TItem =" TreeFoo" Items =" @SearchItems2" ShowSearch =" true" OnSearchAsync =" @OnSearch2Async " IsFixedSearch =" true" style =" height : 180px ;" ></TreeView >
182+ <TreeView TItem =" TreeFoo" Items =" @SearchItems2" ShowSearch =" true" OnSearchAsync =" @OnSearchAsync " IsFixedSearch =" true" style =" height : 180px ;" ></TreeView >
183183</DemoBlock >
184184
185185<DemoBlock Title =" @Localizer[" TreeViewMaxSelectedCountTitle " ]"
Original file line number Diff line number Diff line change @@ -230,38 +230,19 @@ private Task SelectedItemOnChanged(SelectedItem selectedItem)
230230 return ret ;
231231 }
232232
233- private Task OnSearch1Async ( string searchText )
233+ private static async Task < List < TreeViewItem < TreeFoo > > ? > OnSearchAsync ( string searchText )
234234 {
235- if ( string . IsNullOrEmpty ( searchText ) )
236- {
237- SearchItems1 = TreeFoo . GetTreeItems ( ) ;
238- }
239- else
240- {
241- SearchItems1 =
242- [
243- new TreeViewItem < TreeFoo > ( new TreeFoo ( ) { Text = searchText } ) { Text = searchText } ,
244- ] ;
245- }
246- StateHasChanged ( ) ;
247- return Task . CompletedTask ;
248- }
235+ await Task . Delay ( 20 ) ;
249236
250- private Task OnSearch2Async ( string searchText )
251- {
252- if ( string . IsNullOrEmpty ( searchText ) )
253- {
254- SearchItems1 = TreeFoo . GetTreeItems ( ) ;
255- }
256- else
237+ List < TreeViewItem < TreeFoo > > ? items = null ;
238+ if ( ! string . IsNullOrEmpty ( searchText ) )
257239 {
258- SearchItems2 =
240+ items =
259241 [
260242 new TreeViewItem < TreeFoo > ( new TreeFoo ( ) { Text = searchText } ) { Text = searchText } ,
261243 ] ;
262244 }
263- StateHasChanged ( ) ;
264- return Task . CompletedTask ;
245+ return items ;
265246 }
266247
267248 private static async Task < IEnumerable < TreeViewItem < TreeFoo > > > OnExpandVirtualNodeAsync ( TreeViewItem < TreeFoo > node )
Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
151151 /// </summary>
152152 /// <remarks>通过设置 <see cref="ShowSearch"/> 开启</remarks>
153153 [ Parameter ]
154- public Func < string ? , Task < List < TreeViewItem < TItem > > > > ? OnSearchAsync { get ; set ; }
154+ public Func < string ? , Task < List < TreeViewItem < TItem > > ? > > ? OnSearchAsync { get ; set ; }
155155
156156 /// <summary>
157157 /// 获得/设置 页面刷新是否重置已加载数据 默认 false
@@ -345,11 +345,6 @@ protected override void OnParametersSet()
345345 SearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewSearchIcon ) ;
346346 ClearSearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewResetSearchIcon ) ;
347347 LoadingIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewLoadingIcon ) ;
348-
349- if ( IsReset )
350- {
351- _rows = null ;
352- }
353348 }
354349
355350 /// <summary>
@@ -358,12 +353,7 @@ protected override void OnParametersSet()
358353 /// <returns></returns>
359354 protected override async Task OnParametersSetAsync ( )
360355 {
361- if ( Items == null )
362- {
363- // 未提供数据显示 loading
364- return ;
365- }
366-
356+ Items ??= [ ] ;
367357 if ( Items . Count > 0 )
368358 {
369359 await CheckExpand ( Items ) ;
You can’t perform that action at this time.
0 commit comments