Skip to content

Commit 034b9b9

Browse files
committed
doc: 增加示例
1 parent 6f94f71 commit 034b9b9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@
9494

9595
<DemoBlock Title="@Localizer["MultiSelectBindingEnumCollectionTitle"]" Introduction="@Localizer["MultiSelectBindingEnumCollectionIntro"]" Name="BindingEnumCollection">
9696
<section ignore>@((MarkupString)Localizer["MultiSelectBindingEnumCollectionDescription"].Value)</section>
97-
<MultiSelect @bind-Value="@SelectedEnumValues" />
97+
<MultiSelect @bind-Value="@SelectedEnumValues"></MultiSelect>
9898
<section ignore>@(string.Join(",", SelectedEnumValues))</section>
9999
</DemoBlock>
100100

101+
<DemoBlock Title="@Localizer["MultiSelectFlagsEnumTitle"]" Introduction="@Localizer["MultiSelectFlagsEnumIntro"]"
102+
Name="Flags">
103+
<section ignore>@((MarkupString)Localizer["MultiSelectFlagsEnumDescription"].Value)</section>
104+
<MultiSelect @bind-Value="@EnumFoo"></MultiSelect>
105+
</DemoBlock>
106+
101107
<DemoBlock Title="@Localizer["MultiSelectSearchTitle"]" Introduction="@Localizer["MultiSelectSearchIntro"]" Name="Search">
102108
<section ignore>@((MarkupString)Localizer["MultiSelectSearchDescription"].Value)</section>
103109
<MultiSelect Items="@Items" @bind-Value="@SelectedSearchItemsValue" ShowSearch="true" OnSearchTextChanged="@OnSearch" />
@@ -192,7 +198,7 @@
192198
<section ignore>@((MarkupString)Localizer["MultiSelectCascadingDescription"].Value)</section>
193199
<div class="row g-3">
194200
<div class="col-12 col-sm-6">
195-
<Select TValue="string" Items="@CascadingItems2" OnSelectedItemChanged="@OnCascadeBindSelectClick"></Select>
201+
<Select TValue="string" Items="@_cascadingItems2" OnSelectedItemChanged="@OnCascadeBindSelectClick"></Select>
196202
</div>
197203
<div class="col-12 col-sm-6">
198204
<MultiSelect TValue="string" Items="@CascadingItems1" />

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,24 @@ public partial class MultiSelects
6262

6363
private string SelectedItemsValue { get; set; } = "Beijing";
6464

65-
private IEnumerable<string> SelectedArrayValues { get; set; } = Enumerable.Empty<string>();
65+
private IEnumerable<string> SelectedArrayValues { get; set; } = [];
6666

6767
private IEnumerable<EnumEducation> SelectedEnumValues { get; set; } = new List<EnumEducation>
6868
{
6969
EnumEducation.Middle, EnumEducation.Primary
7070
};
7171

72+
private MultiSelectEnumFoo EnumFoo { get; set; } = MultiSelectEnumFoo.One | MultiSelectEnumFoo.Two;
73+
74+
[Flags]
75+
private enum MultiSelectEnumFoo
76+
{
77+
One = 1,
78+
Two = 2,
79+
Three = 4,
80+
Four = 8
81+
}
82+
7283
[NotNull]
7384
private ConsoleLogger? Logger { get; set; }
7485

@@ -101,7 +112,7 @@ private async Task<SelectedItem> OnEditCallback(string value)
101112
{
102113
await Task.Delay(100);
103114

104-
var item = EditableItems.Find(i => i.Text.Equals(value, System.StringComparison.OrdinalIgnoreCase));
115+
var item = EditableItems.Find(i => i.Text.Equals(value, StringComparison.OrdinalIgnoreCase));
105116
if (item == null)
106117
{
107118
item = new SelectedItem(value, value);
@@ -120,7 +131,7 @@ private async Task<SelectedItem> OnEditCallback(string value)
120131
new("Ningbo", "宁波") {GroupName = "华东", Active = true }
121132
];
122133

123-
private readonly SelectedItem[] CascadingItems2 =
134+
private readonly SelectedItem[] _cascadingItems2 =
124135
[
125136
new("", "请选择 ..."),
126137
new("Beijing", "北京") { Active = true },
@@ -209,12 +220,12 @@ private void AddListItems()
209220

210221
private void RemoveListItems()
211222
{
212-
SelectedArrayValues = new[] { "Beijing" };
223+
SelectedArrayValues = ["Beijing"];
213224
}
214225

215226
private void ClearListItems()
216227
{
217-
SelectedArrayValues = Enumerable.Empty<string>();
228+
SelectedArrayValues = [];
218229
}
219230

220231
private void AddArrayItems()
@@ -236,7 +247,7 @@ private IEnumerable<SelectedItem> OnSearch(string searchText)
236247
{
237248
Logger.Log($"{Localizer["MultiSelectSearchLog"]}{searchText}");
238249
SearchItemsSource ??= GenerateItems();
239-
return SearchItemsSource.Where(i => i.Text.Contains(searchText, System.StringComparison.OrdinalIgnoreCase));
250+
return SearchItemsSource.Where(i => i.Text.Contains(searchText, StringComparison.OrdinalIgnoreCase));
240251
}
241252

242253
private Task OnSelectedItemsChanged8(IEnumerable<SelectedItem> items)

0 commit comments

Comments
 (0)