Skip to content

Commit 89dd8e2

Browse files
committed
doc: 更新示例
1 parent 3f1f585 commit 89dd8e2

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

src/BootstrapBlazor.Server/Components/Samples/SelectTrees.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<ValidateForm Model="BindModel">
4040
<div class="row g-3">
4141
<div class="col-12 col-sm-6">
42-
<SelectTree TValue="string" @bind-Value="BindModel.Text" ShowIcon="true" Items="BindItems" />
42+
<SelectTree TValue="string" @bind-Value="BindModel.Text" ShowIcon="true" Items="BindItems" OnExpandNodeAsync="OnExpandNodeAsync" />
4343
</div>
4444
<div class="col-12 col-sm-6 align-self-end">
4545
<Button ButtonType="ButtonType.Submit">@Localizer["SelectTreesClientValidationButtonText"]</Button>

src/BootstrapBlazor.Server/Components/Samples/SelectTrees.razor.cs

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class SelectTrees
1919
[NotNull]
2020
private TreeFoo? Model { get; set; }
2121

22-
private TreeFoo BindModel { get; set; } = new TreeFoo();
22+
private TreeFoo BindModel { get; set; } = new();
2323

2424
[NotNull]
2525
private List<TreeViewItem<string>>? BindItems { get; set; }
@@ -55,35 +55,49 @@ protected override void OnInitialized()
5555

5656
BindModel = new TreeFoo()
5757
{
58-
Text = "Sub Menu Three",
5958
Id = "1090",
6059
ParentId = "1050",
61-
Icon = "fa-solid fa-font-awesome",
62-
IsActive = true
60+
Icon = "fa-solid fa-font-awesome"
6361
};
6462

6563
BindItems =
6664
[
67-
new TreeViewItem<string>("目录一")
68-
{
69-
Text ="目录一",
70-
Icon = "fa-solid fa-folder",
71-
ExpandIcon = "fa-solid fa-folder-open",
72-
Items =
73-
[
74-
new TreeViewItem<string>("子目录一")
75-
{
76-
Text ="子目录一",
77-
Icon = "fa-solid fa-folder",
78-
ExpandIcon = "fa-solid fa-folder-open",
79-
Items =
80-
[
81-
new TreeViewItem<string>("文件一") { Text = "文件一", Icon = "fa-solid fa-file", IsActive = true },
82-
new TreeViewItem<string>("文件二") { Text = "文件二", Icon = "fa-solid fa-file" }
83-
]
84-
}
85-
]
86-
}
87-
];
65+
new TreeViewItem<string>("目录一")
66+
{
67+
Text = "目录一",
68+
Icon = "fa-solid fa-folder",
69+
ExpandIcon = "fa-solid fa-folder-open",
70+
Value = "101",
71+
HasChildren = true
72+
}
73+
];
74+
}
75+
76+
private async Task<IEnumerable<TreeViewItem<string>>> OnExpandNodeAsync(TreeViewItem<string> node)
77+
{
78+
await Task.Delay(500);
79+
80+
if (node.Value == "101")
81+
{
82+
return [new TreeViewItem<string>("子目录一")
83+
{
84+
Text = "子目录一",
85+
Icon = "fa-solid fa-folder",
86+
ExpandIcon = "fa-solid fa-folder-open",
87+
Value = "1001",
88+
HasChildren = true
89+
}];
90+
}
91+
else if (node.Value == "1001")
92+
{
93+
return [
94+
new TreeViewItem<string>("文件一") { Text = "文件一", Icon = "fa-solid fa-file", Value = "10010" },
95+
new TreeViewItem<string>("文件二") { Text = "文件二", Icon = "fa-solid fa-file", Value = "10011" }
96+
];
97+
}
98+
else
99+
{
100+
return [];
101+
}
88102
}
89103
}

0 commit comments

Comments
 (0)