diff --git a/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor b/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor index 95de6b36b85..da24536ef88 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor @@ -428,7 +428,8 @@
@((MarkupString)Localizer["SelectsGenericDesc"].Value)
- +
diff --git a/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor.cs index 131038fcd3a..f21c338730e 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor.cs @@ -251,6 +251,27 @@ private Task OnTimeZoneValueChanged(string timeZoneId) private Foo _selectedFoo = new(); + private async Task TextConvertToValueCallback(string v) + { + // 模拟异步通讯切换线程 + await Task.Delay(10); + + Foo? foo = null; + var item = _genericItems.Find(i => i.Text == v); + if (item == null) + { + var id = _genericItems.Count + 1; + foo = new Foo() { Id = id, Address = $"New Address - {id}" }; + var fooItem = new SelectedItem { Text = v, Value = foo }; + _genericItems.Add(fooItem); + } + else + { + foo = item.Value; + } + return foo!; + } + /// /// 获得事件方法 /// diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 151124684e9..52240212062 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -3266,7 +3266,7 @@ "SelectsVirtualizeDescription": "Component virtual scrolling supports two ways of providing data through Items or OnQueryAsync callback methods", "SelectsGenericTitle": "Generic", "SelectsGenericIntro": "Data source Items supports generics when using SelectedItem<TValue>", - "SelectsGenericDesc": "

Please refer to Design Ideas to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the Foo instance, and the value displayed in the text box on the right is the Address value of the Foo attribute

In this example, the ValueEqualityComparer and CustomKeyAttribute parameters are not set, and the [Key] tag of the Id attribute of Foo is used for equality judgment

", + "SelectsGenericDesc": "

Please refer to Design Ideas to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the Foo instance, and the value displayed in the text box on the right is the Address value of the Foo attribute

In this example, IsEditable=\"true\" and TextConvertToValueCallback parameters are set. When a Foo that does not exist in the original data source is entered, a new Foo instance is added to the data source in the callback method

", "SelectsOnInputChangedCallback": "Callback method for converting input text into corresponding Value in edit mode", "TextConvertToValueCallback": "Callback method when input text changes in edit mode", "SelectsIsEditable": "Whether editable", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 2fc26579bfb..12e9dad5b55 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -3266,7 +3266,7 @@ "SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 Items 或者 OnQueryAsync 回调方法提供数据", "SelectsGenericTitle": "泛型支持", "SelectsGenericIntro": "数据源 Items 使用 SelectedItem<TValue> 时即可支持泛型", - "SelectsGenericDesc": "

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

本例中未设置 ValueEqualityComparer 以及 CustomKeyAttribute 参数,使用 Foo 属性 Id[Key] 标签进行相等判定

", + "SelectsGenericDesc": "

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

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

", "SelectsOnInputChangedCallback": "编辑模式下输入文本转换为对应 Value 回调方法", "TextConvertToValueCallback": "编辑模式下输入文本变化时回调方法", "SelectsIsEditable": "是否可编辑", diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 9c0901e81b8..3496eb35f13 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.7.1-beta02 + 9.7.1-beta03 diff --git a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs index d4cc6a32445..45ae676117b 100644 --- a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs +++ b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs @@ -495,14 +495,12 @@ private async Task OnChange(ChangeEventArgs args) if (val is not null) { - item = new SelectedItem(val, v); - var items = new List>() { item }; - items.AddRange(Items); - Items = items; + // 返回值时,由外部更新 Items 参数 CurrentValue = val; } else { + // 返回空值时恢复上次选中值 await InvokeVoidAsync("resetValue", InputId, SelectedRow?.Text); } }