Traversing the background data to generate tree structure

var getTree=function(treeData,parentId){
var treeArr=[];
for(var i=0; i< treeData.length; i++){
var node=treeData[i];
if(node.sjchannelcode==parentId ){
var newNode={order:node.order,code:node.channelcode,url:node.url,name:node.name,sjchannelcode:node.sjchannelcode,channelcode:getTree(treeData,node.channelcode)};
treeArr.push(newNode);
}
}
return treeArr;
}
// call tree method
var treeArr=getTree(data,sj);
data is the data returned from the background, sj root directory returned by the node parent id

Read More: