Skip to content

Commit 0fd25da

Browse files
committed
refactor: 更新 SelectGeneric 值不存在时的逻辑
1 parent 9189aae commit 0fd25da

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,12 @@ private SelectedItem<TValue>? SelectedRow
291291
var item = Rows.Find(i => Equals(i.Value, Value))
292292
?? Rows.Find(i => i.Active)
293293
?? Rows.Where(i => !i.IsDisabled).FirstOrDefault()
294-
?? GetVirtualizeItem();
294+
?? new SelectedItem<TValue>(Value, DefaultVirtualizeItemText!);
295295

296-
if (item != null)
296+
if (!_init || !DisableItemChangedWhenFirstRender)
297297
{
298-
if (_init && DisableItemChangedWhenFirstRender)
299-
{
300-
301-
}
302-
else
303-
{
304-
_ = SelectedItemChanged(item);
305-
_init = false;
306-
}
298+
_ = SelectedItemChanged(item);
299+
_init = false;
307300
}
308301
return item;
309302
}
@@ -391,11 +384,6 @@ private async Task SearchTextChanged(string val)
391384
}
392385
}
393386

394-
private SelectedItem<TValue>? GetVirtualizeItem()
395-
{
396-
return OnQueryAsync == null ? null : new SelectedItem<TValue>(Value, DefaultVirtualizeItemText ?? CurrentValueAsString);
397-
}
398-
399387
/// <summary>
400388
/// <inheritdoc/>
401389
/// </summary>

0 commit comments

Comments
 (0)