This is a migrated thread and some comments may be shown as answers.

Load items from in memory object array

1 Answer 96 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 22 Sep 2013, 01:28 PM
Is the following supported and if so, how?

If have an in memory object array:

[{
    id: 1,
    name: "item 1",
    parentid: null
},
{
   id: 2,
    name: "item 2",
    parentid: null
},
{
   id: 3,
    name: "subitem for 1",
    parentid: 1
}]

I want the treeview to initially load and display the root items (with parentid null). When a user expands a root node, I want it to display all nodes with that node's id as parentid . I want to be able to build the hierarchy with no limit using this way.

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 24 Sep 2013, 11:36 AM
Hello Roland,


Yes, the described scenario is supported. In order to bind the TreeView to a local JavaScript array of objects, you should first initialize a HierarchicalDataSource from it. By default the items should have a text property for the node and an items property for the children collection (instead of having a parentId property). You could also use custom property names and specify them in the dataTextField configuration property of the TreeView. Both of the approaches are demonstrated in the following demo.

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Roland
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or