diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 6db1c3d67cc21bb05fdd5737056b3f9611e013d5..7a21f344850dbafcaeee0f0478b0337f593f601a 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 5.6.4 + 5.6.5 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.cs b/src/BootstrapBlazor/Components/Table/Table.razor.cs index 2ffa46da688e30bff3f3544dbbd576234ecae851..941b0cd8fb009b025cd218dbdf266b5f0da01ef4 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.cs @@ -738,19 +738,17 @@ namespace BootstrapBlazor.Components /// private IEnumerable? QueryItems { get; set; } - private Lazy>? RowItemsCache { get; set; } + private Lazy>? RowItemsCache { get; set; } private List RowItems { get { - RowItemsCache ??= new(() => Items?.ToList() ?? QueryItems?.ToList() ?? new List()); - return IsTree ? GetTreeRows() : RowItemsCache.Value; + RowItemsCache ??= new(() => Items ?? QueryItems ?? Enumerable.Empty()); + return IsTree ? GetTreeRows() : RowItemsCache.Value.ToList(); } } - - #region 生成 Row 方法 /// /// 获得 指定单元格数据方法 diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs index 8cb3c3ffe58e8579c4d97fdde3385645bdae674a..51e7c43ee4fad8d684df2692c937d96864600184 100644 --- a/src/BootstrapBlazor/Utils/Utility.cs +++ b/src/BootstrapBlazor/Utils/Utility.cs @@ -347,21 +347,19 @@ namespace BootstrapBlazor.Components builder.AddAttribute(6, nameof(CheckboxList>.Items), item.Data); } - //增加非枚举类,手动设定 ComponentType 为 Select 并且 Data 有值 自动生成下拉框 - if (item.Data != null && item.ComponentType != null && item.ComponentType == typeof(Select<>).MakeGenericType(fieldType)) + // 增加非枚举类,手动设定 ComponentType 为 Select 并且 Data 有值 自动生成下拉框 + if (item.Data != null && item.ComponentType == typeof(Select<>).MakeGenericType(fieldType)) { builder.AddAttribute(7, nameof(Select.Items), item.Data); - builder.AddAttribute(8, nameof(Select.Value), fieldValue); - builder.AddAttribute(9, nameof(Select.ValueChanged), fieldValueChanged); - builder.AddAttribute(10, nameof(Select.ValueExpression), valueExpression); - builder.AddAttribute(11, nameof(Select.SkipValidate), false); } - else if (IsValidatableComponent(componentType)) + + // 设置 SkipValidate 参数 + if (IsValidatableComponent(componentType)) { - builder.AddAttribute(12, nameof(IEditorItem.SkipValidate), item.SkipValidate); + builder.AddAttribute(8, nameof(IEditorItem.SkipValidate), item.SkipValidate); } - builder.AddMultipleAttributes(13, CreateMultipleAttributes(fieldType, model, fieldName, item, showLabel, placeholder)); + builder.AddMultipleAttributes(9, CreateMultipleAttributes(fieldType, model, fieldName, item, showLabel, placeholder)); builder.CloseComponent(); } @@ -468,49 +466,36 @@ namespace BootstrapBlazor.Components { var ret = new List>(); var type = Nullable.GetUnderlyingType(fieldType) ?? fieldType; - if (type.IsEnum) - { - // 枚举类型 - // 通过字符串转化为枚举类实例 - var items = type.ToSelectList(); - if (items != null) - { - ret.Add(new("Items", items)); - } - } - else + switch (type.Name) { - switch (type.Name) - { - case nameof(String): - var ph = Utility.GetPlaceHolder(model, fieldName) ?? placeholder; - if (!string.IsNullOrEmpty(ph)) - { - ret.Add(new("placeholder", ph)); - } - if (item.Rows != 0) - { - ret.Add(new("rows", item.Rows)); - } - break; - case nameof(Int16): - case nameof(Int32): - case nameof(Int64): - case nameof(Single): - case nameof(Double): - case nameof(Decimal): - if (item.Step != null) + case nameof(String): + var ph = Utility.GetPlaceHolder(model, fieldName) ?? placeholder; + if (!string.IsNullOrEmpty(ph)) + { + ret.Add(new("placeholder", ph)); + } + if (item.Rows != 0) + { + ret.Add(new("rows", item.Rows)); + } + break; + case nameof(Int16): + case nameof(Int32): + case nameof(Int64): + case nameof(Single): + case nameof(Double): + case nameof(Decimal): + if (item.Step != null) + { + var step = item.Step.ToString(); + if (!string.IsNullOrEmpty(step)) { - var step = item.Step.ToString(); - if (!string.IsNullOrEmpty(step)) - { - ret.Add(new("Step", step)); - } + ret.Add(new("Step", step)); } - break; - default: - break; - } + } + break; + default: + break; } if (showLabel != null)