Question

I have this scenario.

1) Server Side returns a json encoded array having different fields in it along with primary key i.e., id. 2) A kendo treeview is created from that json 3

I want to do this,

1) User browse the tree and select a node. 2) I want to find the primary id of the tree or any other field that is passed from server side to distinguish the selected node.

I hope I deliver the question. Thanks in advance.

Was it helpful?

Solution

Define your select function as:

select    : function (e) {
    // Get clicked node
    var node = e.node;
    // Find it's UID
    var uid = $(node).closest("li").data("uid");
    // Get the item that has this UID
    var item = this.dataSource.getByUid(uid);
}

OTHER TIPS

for find uid you can find it by e.node attribute

     select    : function (e) {  
    var uid = e.node.attributes['data-uid'].value;
                var dataItem = this.dataSource.getByUid(uid);
                alert(dataItem.ProductName);
       }

here is another solution:

onSelect: function(e) {
    var treeView = e.sender,
        dataItem = treeView.dataItem(e.node);
    console.log(dataItem.id);  // retrieves an ID of selected node
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top