diff --git a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor index 4391b40e814..ea29a861520 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor @@ -1,4 +1,4 @@ -@page "/select" +@page "/select" @inject DialogService Dialog @inject IStringLocalizer Localizer @inject IOptions WebsiteOption @@ -366,8 +366,8 @@ Name="ConfirmSelect">
    -
  • @((MarkupString)Localizer["SelectConfifrmSelectDesc1"].Value)
  • -
  • @((MarkupString)Localizer["SelectConfifrmSelectDesc2"].Value)
  • +
  • @((MarkupString)Localizer["SelectConfirmSelectDesc1"].Value)
  • +
  • @((MarkupString)Localizer["SelectConfirmSelectDesc2"].Value)
@@ -452,22 +452,24 @@

1. 使用 OnQueryAsync 作为数据源

-
- +

2. 使用 Items 作为数据源

-
- +
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs index f45e5a3ca00..68f03e8d9a8 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -28,11 +28,13 @@ public sealed partial class Selects new SelectedItem ("Shanghai", "上海") }; - private IEnumerable VirtualItems => Foos.Select(i => new SelectedItem(i.Name!, i.Name!)).ToList(); + private IEnumerable VirtualItems => Foos.Select(i => new SelectedItem(i.Id.ToString(), i.Name!)).ToList(); - private SelectedItem? VirtualItem1 { get; set; } + private int? _virtualItem1 = 2; + private string? VirtualItemText1 => Foos.FirstOrDefault(i => i.Id == 2)?.Name; - private SelectedItem? VirtualItem2 { get; set; } + private int? _virtualItem2 = 3; + private string? VirtualItemText2 => Foos.FirstOrDefault(i => i.Id == 3)?.Name; [NotNull] private List? Foos { get; set; } @@ -76,7 +78,7 @@ private async Task> OnQueryAsync(VirtualizeQueryOption o } return new QueryData { - Items = items.Skip(option.StartIndex).Take(option.Count).Select(i => new SelectedItem(i.Name!, i.Name!)), + Items = items.Skip(option.StartIndex).Take(option.Count).Select(i => new SelectedItem(i.Id.ToString(), i.Name!)), TotalCount = items.Count }; } diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index f0330debff9..9cfea5b081b 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -3030,8 +3030,8 @@ "SelectsShowSearchIntro": "Controls whether the search box is displayed by setting the ShowSearch property, which is not displayed by default false. You can set the IsAutoClearSearchTextWhenCollapsed parameter to control whether the text in the search box is automatically cleared after the drop-down box is collapsed. The default value is false.", "SelectsConfirmSelectTitle": "Drop-down box with confirmation", "SelectsConfirmSelectIntro": "Prevent the current value from changing by setting the OnBeforeSelectedItemChange delegate or setting the ShowSwal parameter to true.", - "SelectConfifrmSelectDesc1": "Set the OnBeforeSelectedItemChange callback method, and pop up a window in the callback method to confirm whether to change the value. If it returns true, the value will be changed, otherwise it will not be changed.", - "SelectConfifrmSelectDesc2": "Set ShowSwal=\"true\" and then confirm the value of the SwalTitle SwalContent parameter using the built-in popup window. In the callback method, you can confirm whether to change the value.", + "SelectConfirmSelectDesc1": "Set the OnBeforeSelectedItemChange callback method, and pop up a window in the callback method to confirm whether to change the value. If it returns true, the value will be changed, otherwise it will not be changed.", + "SelectConfirmSelectDesc2": "Set ShowSwal=\"true\" and then confirm the value of the SwalTitle SwalContent parameter using the built-in popup window. In the callback method, you can confirm whether to change the value.", "SelectsTimeZoneTitle": "Timezone", "SelectsTimeZoneIntro": "Display data of Timezone", "SwalTitle": "The drop-down box value changes", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 6cb4d4b53d6..0c5777c4974 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -3030,8 +3030,8 @@ "SelectsShowSearchIntro": "通过设置 ShowSearch 属性控制是否显示搜索框,默认为 false 不显示搜索框,可以通过设置 IsAutoClearSearchTextWhenCollapsed 参数控制下拉框收起后是否自动清空搜索框内文字,默认值为 false 不清空", "SelectsConfirmSelectTitle": "带确认的下拉框", "SelectsConfirmSelectIntro": "通过设置 OnBeforeSelectedItemChange 委托或者设置 ShowSwal 参数值为 true,阻止当前值的改变。", - "SelectConfifrmSelectDesc1": "设置 OnBeforeSelectedItemChange 回调方法,在回调方法内自己弹窗确认是否更改值,返回 true 时更改,否则不更改", - "SelectConfifrmSelectDesc2": "设置 ShowSwal=\"true\" 然后通过设置 SwalTitle SwalContent 参数值使用内置弹窗进行确认即可,在回调方法内自己弹窗确认是否更改值", + "SelectConfirmSelectDesc1": "设置 OnBeforeSelectedItemChange 回调方法,在回调方法内自己弹窗确认是否更改值,返回 true 时更改,否则不更改", + "SelectConfirmSelectDesc2": "设置 ShowSwal=\"true\" 然后通过设置 SwalTitle SwalContent 参数值使用内置弹窗进行确认即可,在回调方法内自己弹窗确认是否更改值", "SelectsTimeZoneTitle": "时区下拉框", "SelectsTimeZoneIntro": "下拉框展现时区数据", "SwalTitle": "下拉框值变更", @@ -3064,7 +3064,7 @@ "SelectsIsEditableDesc": "开启可编辑功能后,输入值如果候选项中没有时,可以通过 TextConvertToValueCallback 回调方法返回新值,可以通过 OnInputChangedCallback 回调对 Items 数据源进行更新,防止页面刷新后输入值丢失", "SelectsVirtualizeTitle": "虚拟滚动", "SelectsVirtualizeIntro": "通过设置 IsVirtualize 参数开启组件虚拟功能特性", - "SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 Items 或者 OnQueryAsync 回调方法提供数据", + "SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 Items 或者 OnQueryAsync 回调方法提供数据。如果数据源使用 OnQueryAsync 回调获得时只有当下拉框展开时才会触发,,如果数据源使用 Items 时,由于性能问题(有些开发会把几百万条数据给 Items)内部并没有进行查找选中项,所以需要设置 DefaultVirtualizeItemText 值应对首次加载时不知道如何显示问题", "SelectsGenericTitle": "泛型支持", "SelectsGenericIntro": "数据源 Items 使用 SelectedItem<TValue> 时即可支持泛型", "SelectsGenericDesc": "

请参考 设计思路 理解此功能。本例中通过选择下拉框选项,得到的值为 Foo 实例,右侧文本框内显示值为 Foo 属性 Address

本例中设置 IsEditable=\"true\" 以及 TextConvertToValueCallback 参数,录入原数据源中不存在的 Foo 时,在 回调方法中添加新 Foo 实例到数据源中

", diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index b6a681b3de5..2682b60667c 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -500,7 +500,7 @@ private async Task OnChange(ChangeEventArgs args) var item = GetItemWithEnumValue() ?? Rows.Find(i => i.Value == CurrentValueAsString) ?? Rows.Find(i => i.Active) - ?? Rows.FirstOrDefault(i => !i.IsDisabled); + ?? Rows.Find(i => !i.IsDisabled); return item; } }