Skip to content

Commit 038d9eb

Browse files
committed
doc: 更新示例
1 parent 7bda982 commit 038d9eb

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@
428428
<section ignore>@((MarkupString)Localizer["SelectsGenericDesc"].Value)</section>
429429
<div class="row">
430430
<div class="col-12 col-sm-6">
431-
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo" IsEditable="true"></SelectGeneric>
431+
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo"
432+
IsEditable="true" TextConvertToValueCallback="TextConvertToValueCallback"></SelectGeneric>
432433
</div>
433434
<div class="col-12 col-sm-6">
434435
<Display Value="_selectedFoo.Address"></Display>

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ private Task OnTimeZoneValueChanged(string timeZoneId)
251251

252252
private Foo _selectedFoo = new();
253253

254+
private async Task<Foo> TextConvertToValueCallback(string v)
255+
{
256+
// 模拟异步通讯切换线程
257+
await Task.Delay(10);
258+
259+
Foo? foo = null;
260+
var item = _genericItems.Find(i => i.Text == v);
261+
if (item == null)
262+
{
263+
var id = _genericItems.Count + 1;
264+
foo = new Foo() { Id = id, Address = $"New Address - {id}" };
265+
var fooItem = new SelectedItem<Foo> { Text = v, Value = foo };
266+
_genericItems.Add(fooItem);
267+
}
268+
else
269+
{
270+
foo = item.Value;
271+
}
272+
return foo!;
273+
}
274+
254275
/// <summary>
255276
/// 获得事件方法
256277
/// </summary>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "Component virtual scrolling supports two ways of providing data through <code>Items</code> or <code>OnQueryAsync</code> callback methods",
32673267
"SelectsGenericTitle": "Generic",
32683268
"SelectsGenericIntro": "Data source <code>Items</code> supports generics when using <code>SelectedItem&lt;TValue&gt;</code>",
3269-
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, the <code>ValueEqualityComparer</code> and <code>CustomKeyAttribute</code> parameters are not set, and the <code>[Key]</code> tag of the <code>Id</code> attribute of <code>Foo</code> is used for equality judgment</p>",
3269+
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, <code>IsEditable=\"true\"</code> and <code>TextConvertToValueCallback</code> parameters are set. When a <code>Foo</code> that does not exist in the original data source is entered, a new <code>Foo</code> instance is added to the data source in the <code></code> callback method</p>",
32703270
"SelectsOnInputChangedCallback": "Callback method for converting input text into corresponding Value in edit mode",
32713271
"TextConvertToValueCallback": "Callback method when input text changes in edit mode",
32723272
"SelectsIsEditable": "Whether editable",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据",
32673267
"SelectsGenericTitle": "泛型支持",
32683268
"SelectsGenericIntro": "数据源 <code>Items</code> 使用 <code>SelectedItem&lt;TValue&gt;</code> 时即可支持泛型",
3269-
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中未设置 <code>ValueEqualityComparer</code> 以及 <code>CustomKeyAttribute</code> 参数,使用 <code>Foo</code> 属性 <code>Id</code> <code>[Key]</code> 标签进行相等判定</p>",
3269+
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中设置 <code>IsEditable=\"true\"</code> 以及 <code>TextConvertToValueCallback</code> 参数,录入原数据源中不存在的 <code>Foo</code> 时,在 <code></code> 回调方法中添加新 <code>Foo</code> 实例到数据源中</p>",
32703270
"SelectsOnInputChangedCallback": "编辑模式下输入文本转换为对应 Value 回调方法",
32713271
"TextConvertToValueCallback": "编辑模式下输入文本变化时回调方法",
32723272
"SelectsIsEditable": "是否可编辑",

0 commit comments

Comments
 (0)