Skip to content

Commit c814a33

Browse files
committed
Revert "refactor: 更改变量可见性"
This reverts commit 0c234b2.
1 parent 7f36c26 commit c814a33

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ protected async Task QueryData(bool triggerByPagination = false)
484484
else
485485
{
486486
ResetSelectedRows(Items);
487-
_rowsCache = null;
487+
RowsCache = null;
488488
}
489489
return;
490490

@@ -513,7 +513,7 @@ async Task OnQuery(QueryPageOptions queryOption)
513513
}
514514

515515
// 更新数据后清除缓存防止新数据不显示
516-
_rowsCache = null;
516+
RowsCache = null;
517517
return;
518518

519519
void ProcessData()

src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ protected async Task<bool> SaveModelAsync(EditContext context, ItemChangedType c
648648
if (DynamicContext != null)
649649
{
650650
await DynamicContext.SetValue(context.Model);
651-
_rowsCache = null;
651+
RowsCache = null;
652652
valid = true;
653653
}
654654
else
@@ -1095,7 +1095,7 @@ private void ResetDynamicContext()
10951095

10961096
private void QueryDynamicItems(QueryPageOptions queryOption, IDynamicObjectContext? context)
10971097
{
1098-
_rowsCache = null;
1098+
RowsCache = null;
10991099
if (context != null)
11001100
{
11011101
var items = context.GetItems();

src/BootstrapBlazor/Components/Table/Table.razor.TreeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected Func<Task> ToggleTreeRow(TItem item) => async () =>
106106
IsLoadChildren = false;
107107

108108
// 清除缓存
109-
_rowsCache = null;
109+
RowsCache = null;
110110

111111
// 更新 UI
112112
StateHasChanged();

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ protected override void OnParametersSet()
935935
IsPagination = false;
936936
}
937937

938-
_rowsCache = null;
938+
RowsCache = null;
939939

940940
if (IsExcel)
941941
{
@@ -1273,17 +1273,21 @@ protected async Task LoopQueryAsync()
12731273
/// </summary>
12741274
private IEnumerable<TItem> QueryItems { get; set; } = [];
12751275

1276-
private List<TItem>? _rowsCache;
1276+
[NotNull]
1277+
private List<TItem>? RowsCache { get; set; }
12771278

12781279
/// <summary>
12791280
/// 获得 当前表格所有 Rows 集合
12801281
/// </summary>
1281-
private List<TItem> Rows
1282+
public List<TItem> Rows
12821283
{
12831284
get
12841285
{
1285-
_rowsCache ??= IsTree ? TreeRows.GetAllItems() : [.. (Items ?? QueryItems)];
1286-
return _rowsCache;
1286+
// https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I5JG5D
1287+
// 如果 QueryItems 无默认值
1288+
// 页面 OnInitializedAsync 二刷再 OnAfterRender 过程中导致 QueryItems 变量为空 ToList 报错
1289+
RowsCache ??= IsTree ? TreeRows.GetAllItems() : [.. (Items ?? QueryItems)];
1290+
return RowsCache;
12871291
}
12881292
}
12891293

0 commit comments

Comments
 (0)