how to add and get a custom value

HI

I need to add  and get  custom property like

sample data;

var a = [{ id:1,pid:1,name:'hi',attribute:'att1',attribute2:'att2' },

{ id:2,pid:1,name:'hi',attribute:'att2',attribute2:'att3' } ];

I am taking all checked nodes from the tree

var chknodes =  tree.getAllCheckedNodes();

chknodes.forEach(function(id){

// with this id I have to get the value of attribute and attribute2

})

I used getTreedata but it returns [] sometimes.

I tried getNode(id) but it returns only the id, name,pid. 

so how do i get the custom property


1 Reply 1 reply marked as answer

SM Shalini Maragathavel Syncfusion Team September 30, 2021 01:07 PM UTC

Hi Swethaa, 

Greetings from Syncfusion support. 

Based on your query, we suspect that you need to get the checked nodes data source fields of TreeView. You can achieve your requirement by passing the checked nodes Id in the getTreeData method of TreeView as demonstrated in the below code snippet. 
var treeObj = new ej.navigations.TreeView({ 
  fields: {  }, 
  nodeChecked: function (args) { 
    var checkednodes = this.getAllCheckedNodes(); //to get the checked nodes id. 
    for (var i = 0; i < checkednodes.length; i++) { 
      var data = this.getTreeData(checkednodes[i]); //to get checked node data 
      var attribute = data[0].attribute; 
      var attribute1 = data[0].attribute2; 
      console.log(attribute); 
      console.log(attribute1); 
    } 
  }, 
}); 

Please find the below sample for your reference, 
Please get back to us if you need further assistance.

Regards, 
Shalini M. 


Marked as answer
Loader.
Up arrow icon