多级树视图

发布于 2024-11-02 11:22:12 字数 1767 浏览 0 评论 0原文

我正在努力将三个级别绑定到我的 telerik treeView

+Directories 

  *Archives

     -Documents

  *Directories

这是我的代码:

 <% Html.Telerik().TreeView()
           .Name("TeleTreeView")
           .DragAndDrop(true)
           .ExpandAll(true)
            .BindTo(Model, mappings =>
              {
                  mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, directory) =>
                          {
                              item.Text = (string)directory.DirectoryName;
                              item.Value = (string)directory.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })


                          //Sub Directories
                          .Children(directory => directory.Directory1));
                          mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, dir) =>
                          {
                              item.Text = dir.DirectoryName;
                              item.Value = (string)dir.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })

                          //Sub archives
                            .Children(directory => directory.Archives));
                            mappings.For<SARS.Archive>(binding => binding
                            .ItemDataBound((item, arch) =>
                            {
                                item.Text = arch.ArchiveName;
                             }));

        })
              .Render();%>

编辑:问题是我没有获得档案级别。 我应该怎么办?

I'm working on binding three levels to my telerik treeView

+Directories 

  *Archives

     -Documents

  *Directories

This is my code:

 <% Html.Telerik().TreeView()
           .Name("TeleTreeView")
           .DragAndDrop(true)
           .ExpandAll(true)
            .BindTo(Model, mappings =>
              {
                  mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, directory) =>
                          {
                              item.Text = (string)directory.DirectoryName;
                              item.Value = (string)directory.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })


                          //Sub Directories
                          .Children(directory => directory.Directory1));
                          mappings.For<SARS.Directory>(binding => binding
                          .ItemDataBound((item, dir) =>
                          {
                              item.Text = dir.DirectoryName;
                              item.Value = (string)dir.NodeID;
                              item.ImagUrl="~/Images/Folder-Add-icon.png";
                          })

                          //Sub archives
                            .Children(directory => directory.Archives));
                            mappings.For<SARS.Archive>(binding => binding
                            .ItemDataBound((item, arch) =>
                            {
                                item.Text = arch.ArchiveName;
                             }));

        })
              .Render();%>

Edit:The problem is that I'm not getting the Archives level.
What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把梦留给海 2024-11-09 11:22:12

Directory1应该包含一个像Archives这样的类的Iennumerable列表,那么很容易获得子节点。我尝试过最多 4 级层次结构。

Directory1 should contains a Iennumerable list of a class like Archives , then its easy to get the child nodes . I have tried upto 4 levels of hierarchy.

诺曦 2024-11-09 11:22:12

目前不支持此功能。您不能指定不同类型的子项。第二次调用 Children() 将覆盖前一个。

This is not currently supported. You cannot specify children of different type. The second call to Children() will overwrite the previous one.

上课铃就是安魂曲 2024-11-09 11:22:12

我最近遇到了同样的问题,一些节点子节点将具有不同和/或混合类型:

 - TypeA
     - TypeA
           - TypeA + TypeB
           - TypeB

我解决这个问题的方法是简单地引入各种类型的接口,然后将树视图绑定到该接口:

public interface ITreeNode
{
    int Id { get; }
    string Name { get; }
    IEnumerable<ITreeNode> ChildrenNodes { get; }
}


Html.Kendo().TreeView()
    .BindTo(Model.CurrentHierarchy, mappings => 
    {
        mappings.For<ITreeNode>(binding => binding.ItemDataBound((item, node) =>
        {
           item.Id = node.Id.ToString();
           item.Text = node.Name;                
        })
        .Children(o => o.ChildrenNodes))
     });

I recently had the same problem whereby some nodes children would be of a different and/or mixed type:

 - TypeA
     - TypeA
           - TypeA + TypeB
           - TypeB

The way I resolved this was to simply introduce an interface on the various types and then bind the treeview to the interface:

public interface ITreeNode
{
    int Id { get; }
    string Name { get; }
    IEnumerable<ITreeNode> ChildrenNodes { get; }
}


Html.Kendo().TreeView()
    .BindTo(Model.CurrentHierarchy, mappings => 
    {
        mappings.For<ITreeNode>(binding => binding.ItemDataBound((item, node) =>
        {
           item.Id = node.Id.ToString();
           item.Text = node.Name;                
        })
        .Children(o => o.ChildrenNodes))
     });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文