Skip to content

Commit df7a394

Browse files
committed
refactor: 增加私有变量缓存上次虚拟条目结果
1 parent d492d51 commit df7a394

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ public partial class Select<TValue> : ISelect, IModelEqualityComparer<TValue>
212212

213213
private List<SelectedItem>? _itemsCache;
214214

215+
private ItemsProviderResult<SelectedItem> _result;
216+
215217
private List<SelectedItem> Rows
216218
{
217219
get
@@ -317,7 +319,8 @@ private async ValueTask<ItemsProviderResult<SelectedItem>> LoadItems(ItemsProvid
317319

318320
TotalCount = data.TotalCount;
319321
var items = data.Items ?? [];
320-
return new ItemsProviderResult<SelectedItem>(items, TotalCount);
322+
_result = new ItemsProviderResult<SelectedItem>(items, TotalCount);
323+
return _result;
321324

322325
int GetCountByTotal() => TotalCount == 0 ? request.Count : Math.Min(request.Count, TotalCount - request.StartIndex);
323326
}
@@ -488,12 +491,16 @@ private async Task OnClearValue()
488491
await OnClearAsync();
489492
}
490493

494+
SelectedItem? item;
491495
if (OnQueryAsync != null)
492496
{
493497
await VirtualizeElement.RefreshDataAsync();
498+
item = _result.Items.FirstOrDefault();
499+
}
500+
else
501+
{
502+
item = Items.FirstOrDefault();
494503
}
495-
496-
var item = Items.FirstOrDefault();
497504
if (item != null)
498505
{
499506
await SelectedItemChanged(item);

0 commit comments

Comments
 (0)