This question is locked. New answers and comments are not allowed.
Hello!
I'm trying to use the TreeView MVC component but am unable to populate children as i'm using different application architecture in my case.
| public class Node |
| { |
| public virtual Node ParentNode { get; set; } |
| public virtual int NodeId { get; set; } |
| } |
| public class NodeRepository |
| { |
| private static readonly List<Node> InternalStorage = new List<Node>(); |
| //where i have methods |
| public void Add(Node node) { // logic here } |
| public Node GetRoot() { // logic here } |
| public IEnumerable<Node> GetChildren(Node node) { // logic here } |
| public IEnumerable<Node> GetSiblings(Node node) { // logic here } |
| public Node GetById(int nodeId) { // logic here } |
| public IEnumerable<Node> GetAncestors(Node node) { // logic here } |
| public void Remove(Node node) { // logic here } |
| } |
I'm wondering...is it possible to populate TreeView with this kind of application architecture?
I can send the data from controller to view via:
| ViewData.Model = _nodeRepository.GetChildren(rootNode); |
| return View(); |
And then in the view i can populate the first level of nodes, but am unable to do that for all the children since my nodes don't have direct reference to descendants.
| <%= Html.Telerik().TreeView() |
| .Name("TreeView") |
| .BindTo(Model, mappings => |
| { |
| mappings.For<Node>(binding => binding |
| .ItemDataBound((item, node) => |
| { |
| item.Text = node.Title; |
| }) |
| // Below this, does not work |
| //.Children(node => node.Children)); |
| }) |
| %> |
Is it possible to do that with my architecture of the application? If not, do you have a specification of TreeNode so i could see a different implementation and the requirements to make it work with your TreeView.
Thank you for your answer.