0

我有一个 TechDocBranch 项目列表,我想在Kendo Blazor TreeList中将其表示为一棵树。

public class TechDocBranch
{
    public long ID { get; set; }
    public long ParentID { get; set; }
    public string Title { get; set; }

    // some another fields
}

我写了以下代码:

<TelerikTreeList Data="@TechDocBranches"
                 IdField="@nameof(TechDocBranch.ID)"
                 ParentIdField="@nameof(TechDocBranch.ParentID)">
    <TreeListColumns>
        <TreeListColumn Field="@nameof(TechDocBranch.ID)"></TreeListColumn>
        <TreeListColumn Field="@nameof(TechDocBranch.Title)"></TreeListColumn>
        <TreeListColumn Field="@nameof(TechDocBranch.ParentID)"></TreeListColumn>
    </TreeListColumns>
</TelerikTreeList>

@code {
    public List<TechDocBranch> TechDocBranches;

    protected override async Task OnInitializedAsync()
    {
        TechDocBranches = await ProductionService.GetTechDocBranches();
    }
}

但它给了我一张简单的桌子,而不是一棵树。我尝试使用 TreeView(仅更改了 html):

<TelerikTreeView Data="@TechDocBranches">
    <TreeViewBindings>
        <TreeViewBinding 
                         IdField="@nameof(TechDocBranch.ID)" 
                         TextField="@nameof(TechDocBranch.Title)" 
                         ParentIdField="@nameof(TechDocBranch.ParentID)">
        </TreeViewBinding>
    </TreeViewBindings>
</TelerikTreeView>

工作正常并给了我树。

我应该怎么做才能在 TreeList 中获取树?

4

1 回答 1

0

您必须为任何列添加可扩展属性才能解决此问题。例如:

<TreeListColumn Field="@nameof(TDB.ID)" Expandable="true"></TreeListColumn>

PS 请注意,与 Kendo TreeView 不同,Kendo TreeList 在大数据量下运行缓慢。(Blazor 版本 2.18)

于 2020-10-26T05:54:39.180 回答