-
-
+
diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj
index fd08f5e5aa8..37a81be71e0 100644
--- a/src/BootstrapBlazor/BootstrapBlazor.csproj
+++ b/src/BootstrapBlazor/BootstrapBlazor.csproj
@@ -1,7 +1,7 @@
- 9.3.1-beta11
+ 9.3.1-beta16
diff --git a/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs b/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
index 8787476f1cf..c9f399837f4 100644
--- a/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
+++ b/src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
@@ -316,6 +316,8 @@ public partial class TreeView : IModelEqualityComparer
private string? EnableKeyboardString => EnableKeyboard ? "true" : null;
+ private bool _shouldRender = true;
+
private static string? GetItemTextClassString(TreeViewItem item) => CssBuilder.Default("tree-node-text")
.AddClass(item.CssClass)
.Build();
@@ -355,13 +357,15 @@ protected override void OnParametersSet()
protected override async Task OnParametersSetAsync()
{
_rows = null;
- TreeNodeStateCache.Reset();
-
if (Items != null)
{
if (Items.Count > 0)
{
+ _shouldRender = false;
await CheckExpand(Items);
+ _shouldRender = true;
+
+ _rows = null;
}
if (ShowCheckbox && (AutoCheckParent || AutoCheckChildren))
@@ -402,6 +406,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
}
}
+ ///
+ ///
+ ///
+ ///
+ protected override bool ShouldRender() => _shouldRender;
+
///
///
///
diff --git a/src/BootstrapBlazor/Misc/ExpandableNodeCache.cs b/src/BootstrapBlazor/Misc/ExpandableNodeCache.cs
index 8a8d61b9a1e..409e3380932 100644
--- a/src/BootstrapBlazor/Misc/ExpandableNodeCache.cs
+++ b/src/BootstrapBlazor/Misc/ExpandableNodeCache.cs
@@ -99,7 +99,7 @@ public async Task CheckExpandAsync(TNode node, Func>(pb =>
+ {
+ pb.Add(a => a.Items, items);
+ pb.Add(a => a.OnExpandNodeAsync, item =>
+ {
+ return OnExpandNodeAsync(item.Value);
+ });
+ });
+ var nodes = cut.FindAll(".tree-node");
+ Assert.Single(nodes);
+
+ // 展开节点
+ var bar = cut.Find(".fa-caret-right.visible");
+ await cut.InvokeAsync(() => bar.Click());
+
+ cut.WaitForAssertion(() =>
+ {
+ nodes = cut.FindAll(".tree-node");
+ Assert.Equal(3, nodes.Count);
+ });
+
+ // 重新渲染
+ items = TreeFoo.GetTreeItems();
+ items.RemoveAt(1);
+ items.RemoveAt(1);
+ items[0].HasChildren = true;
+ cut.SetParametersAndRender(pb =>
+ {
+ pb.Add(a => a.Items, items);
+ });
+
+ cut.WaitForAssertion(() =>
+ {
+ nodes = cut.FindAll(".tree-node");
+ Assert.Equal(3, nodes.Count);
+ });
+
+ // 重新渲染
+ items = TreeFoo.GetTreeItems();
+ items.RemoveAt(1);
+ items.RemoveAt(1);
+ items[0].HasChildren = false;
+ items[0].Items =
+ [
+ new(new TreeFoo() { Id = "101", ParentId = "1010" })
+ {
+ Text = "懒加载子节点11",
+ HasChildren = true
+ },
+ new(new TreeFoo(){ Id = "102", ParentId = "1010" })
+ {
+ Text = "懒加载子节点22"
+ }
+ ];
+ cut.SetParametersAndRender(pb =>
+ {
+ pb.Add(a => a.Items, items);
+ });
+ cut.WaitForAssertion(() =>
+ {
+ nodes = cut.FindAll(".tree-node");
+ Assert.Equal(3, nodes.Count);
+ });
+ }
+
[Fact]
public async Task OnExpandRowAsync_CheckCascadeState_Ok()
{