diff --git a/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs b/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs index b3c4ec90b64..6fd7f2c6a03 100644 --- a/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs +++ b/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs @@ -351,6 +351,7 @@ protected override async Task OnParametersSetAsync() { if (IsReset) { + _rows = null; TreeNodeStateCache.Reset(); } else @@ -822,35 +823,37 @@ private void OnTouchEnd() TouchStart = false; } - private List> Rows => GetTreeRows(Items); - private List>? _rows = null; -#if NET9_0_OR_GREATER - private readonly Lock _object = new(); -#else - private readonly object _object = new(); -#endif + private List> Rows + { + get + { + _rows ??= GetTreeRows(Items); + return _rows; + } + } - private List> GetTreeRows(List> items) + /// + /// 将带层次结构的数据转换为扁平化数据 + /// + /// + /// + private static List> GetTreeRows(List> items) { - lock (_object) + var rows = new List>(); + if (items != null) { - var rows = new List>(); - if (items != null) + foreach (var item in items) { - foreach (var item in items) + rows.Add(item); + if (item.IsExpand) { - rows.Add(item); - if (item.IsExpand) - { - rows.AddRange(GetTreeRows(item.Items)); - } + rows.AddRange(GetTreeRows(item.Items)); } } - _rows ??= rows; - return rows; } + return rows; } private static string? GetTreeRowStyle(TreeViewItem item) diff --git a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs index 083de5700f7..967356dc7b0 100644 --- a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs +++ b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs @@ -31,8 +31,8 @@ public static async Task LoadModule(this IJSRuntime jsRuntime, string fileName = $"{fileName}?v={version}"; } - var jSObjectReference = await jsRuntime.InvokeAsync(identifier: "import", fileName); - return new JSModule(jSObjectReference); + var jSObjectReference = await jsRuntime.InvokeAsync(identifier: "import", fileName); + return new JSModule(jSObjectReference); } ///