Skip to content

Commit 7bdc67f

Browse files
committed
refactor: 更改绑定值为可为空
1 parent 28f5230 commit 7bdc67f

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/BootstrapBlazor.Server/Components/Samples/Selects.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@
457457
ShowSearch="_showSearch" IsClearable="_isClearable"></Select>
458458
</div>
459459
<div class="col-6">
460-
<Display TValue="int" Value="@_virtualItem1"></Display>
460+
<Display TValue="int?" Value="@_virtualItem1"></Display>
461461
</div>
462462
</div>
463463

@@ -469,7 +469,7 @@
469469
ShowSearch="_showSearch" IsClearable="_isClearable"></Select>
470470
</div>
471471
<div class="col-6">
472-
<Display TValue="int" Value="@_virtualItem2"></Display>
472+
<Display TValue="int?" Value="@_virtualItem2"></Display>
473473
</div>
474474
</div>
475475
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public sealed partial class Selects
3030

3131
private IEnumerable<SelectedItem> VirtualItems => Foos.Select(i => new SelectedItem(i.Id.ToString(), i.Name!)).ToList();
3232

33-
private int _virtualItem1 = 2;
34-
private string? VirtualItemText1 => VirtualItems.FirstOrDefault(i => i.Value == "2")?.Text;
33+
private int? _virtualItem1 = 2;
34+
private string? VirtualItemText1 => Foos.FirstOrDefault(i => i.Id == 2)?.Name;
3535

36-
private int _virtualItem2 = 2;
37-
private string? VirtualItemText2 => VirtualItems.FirstOrDefault(i => i.Value == "2")?.Text;
36+
private int? _virtualItem2 = 3;
37+
private string? VirtualItemText2 => Foos.FirstOrDefault(i => i.Id == 3)?.Name;
3838

3939
[NotNull]
4040
private List<Foo>? Foos { get; set; }
@@ -78,7 +78,7 @@ private async Task<QueryData<SelectedItem>> OnQueryAsync(VirtualizeQueryOption o
7878
}
7979
return new QueryData<SelectedItem>
8080
{
81-
Items = items.Skip(option.StartIndex).Take(option.Count).Select(i => new SelectedItem(i.Name!, i.Name!)),
81+
Items = items.Skip(option.StartIndex).Take(option.Count).Select(i => new SelectedItem(i.Id.ToString(), i.Name!)),
8282
TotalCount = items.Count
8383
};
8484
}

0 commit comments

Comments
 (0)