国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Blazor實現(xiàn)高級表單功能

2022-07-17 13:29 作者:限量版范兒  | 我要投稿

思路

  1. 添加Form組件類,提供Validate,OnSubmit等

  2. 添加Field組件基類,提供Id,Label,Value等

  3. 添加Field子組件Text、Password等表單字段組件

  4. 添加FormContext類,存儲表單及字段數(shù)據(jù)

  5. 使用級聯(lián)值組件傳遞FormContext實例(關鍵)

Form組件

public class FormContext { ? ?public Dictionary<string, Field> Fields { get; } } public class Form : BaseComponent { ? ?[Parameter] public RenderFragment ChildContent { get; set; } ? ?public FormContext Context { get; } ? ?public bool Validate() { return false; } ? ? ? ?protected override void BuildRenderTree(RenderTreeBuilder builder) { ? ? ? ?builder.Div(attr => { ? ? ? ? ? ?attr.Class(Style); ? ? ? ? ? ?builder.Component<CascadingValue<FormContext>>(attr => { ? ? ? ? ? ? ? ?attr.Add(nameof(CascadingValue<FormContext>.Value), Context); ? ? ? ? ? ? ? ?attr.Add(nameof(CascadingValue<FormContext>.ChildContent), ChildContent); ? ? ? ? ? ?}); ? ? ? ?}); ? ?} }

Field組件

public class Field : BaseComponent { ? ?[Parameter] public string Id { get; set; } ? ?[Parameter] public string Label { get; set; } ? ?[CascadingParameter] ? ?protected FormContext Context { get; set; } ? ?protected override void OnInitialized() { ? ? ? ?base.OnInitialized(); ? ? ? ?Context.Fields[Id] = this; ? ?} ? ?protected override void BuildRenderTree(RenderTreeBuilder builder) { ? ?} ? ?protected virtual void BuidChildContent(RenderTreeBuilder builder) {} } public class Text : Field { ? ?[Parameter] public string Icon { get; set; } ? ?[Parameter] public string Placeholder { get; set; } ? ?protected override void BuidChildContent(RenderTreeBuilder builder) { ? ?} } public class Password : Field { ? ?[Parameter] public string Icon { get; set; } ? ?[Parameter] public string Placeholder { get; set; } ? ?protected override void BuidChildContent(RenderTreeBuilder builder) { ? ?} }

Form示例

<Form @ref="form"> ? ?<Text Id="UserName" Icon="fa fa-user-o" Placeholder="用戶名" /> ? ?<Password Id="Password" Icon="fa fa-lock" Placeholder="密碼" /> ? ?<Button Text="登 錄" OnClick="OnLogin" /> </Form> @code { ? ?private Form form; ? ?private void OnLogin() { ? ? ? ?if (!form.Validate()) ? ? ? ? ? ?return; ? ?} }

來源:https://www.dianjilingqu.com/203138.html

Blazor實現(xiàn)高級表單功能的評論 (共 條)

分享到微博請遵守國家法律
泗水县| 榆树市| 保靖县| 赞皇县| 孟村| 白银市| 抚宁县| 河西区| 五家渠市| 麻栗坡县| 江北区| 武汉市| 苏州市| 江安县| 邓州市| 利辛县| 鲁甸县| 上蔡县| 黎城县| 姚安县| 枣庄市| 元江| 盐亭县| 金溪县| 保亭| 来凤县| 阳原县| 陆丰市| 泽州县| 阿城市| 渝中区| 和林格尔县| 南靖县| 富源县| 新巴尔虎左旗| 高碑店市| 雷州市| 澄江县| 榆社县| 明溪县| 广水市|