开发者

Multi level treeView

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
                          .ItemDataBoun开发者_运维问答d((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?


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.


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


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))
     });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜