Skip to content

Commit 9c89848

Browse files
committed
refactor: 修复首次加载问题
1 parent 8b246b8 commit 9c89848

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ protected override void OnParametersSet()
323323
SelectedItem = null;
324324
}
325325

326+
/// <summary>
327+
/// <inheritdoc/>
328+
/// </summary>
329+
/// <returns></returns>
330+
protected override async Task OnAfterRenderAsync(bool firstRender)
331+
{
332+
await base.OnAfterRenderAsync(firstRender);
333+
334+
if (firstRender)
335+
{
336+
await RefreshVirtualizeElement();
337+
StateHasChanged();
338+
}
339+
}
340+
326341
/// <summary>
327342
/// 获得/设置 数据总条目
328343
/// </summary>
@@ -356,7 +371,12 @@ private async Task SearchTextChanged(string val)
356371
{
357372
_itemsCache = null;
358373
SearchText = val;
359-
if (OnQueryAsync != null)
374+
await RefreshVirtualizeElement();
375+
}
376+
377+
private async Task RefreshVirtualizeElement()
378+
{
379+
if (IsVirtualize && OnQueryAsync != null)
360380
{
361381
// 通过 ItemProvider 提供数据
362382
await VirtualizeElement.RefreshDataAsync();

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ protected override void OnParametersSet()
346346
SelectedItem = null;
347347
}
348348

349+
/// <summary>
350+
/// <inheritdoc/>
351+
/// </summary>
352+
/// <returns></returns>
353+
protected override async Task OnAfterRenderAsync(bool firstRender)
354+
{
355+
await base.OnAfterRenderAsync(firstRender);
356+
357+
if (firstRender)
358+
{
359+
await RefreshVirtualizeElement();
360+
StateHasChanged();
361+
}
362+
}
363+
349364
/// <summary>
350365
/// 获得/设置 数据总条目
351366
/// </summary>
@@ -379,8 +394,12 @@ private async Task SearchTextChanged(string val)
379394
{
380395
SearchText = val;
381396
_itemsCache = null;
397+
await RefreshVirtualizeElement();
398+
}
382399

383-
if (OnQueryAsync != null)
400+
private async Task RefreshVirtualizeElement()
401+
{
402+
if (IsVirtualize && OnQueryAsync != null)
384403
{
385404
// 通过 ItemProvider 提供数据
386405
await VirtualizeElement.RefreshDataAsync();

0 commit comments

Comments
 (0)