I'am developing a web application and i'am using dynatree for structure.
EX:
Node 1
+ Node 1.1
+ Node 1.1.1
+ Node 1.1.2
+ Node 1.1.3
I want to add child node (+Node 1.1.3.1) in this, like
Node 1
+ Node 1.1
+ Node 1.1.1
+ Node 1.1.2
+ Node 1.1.3
+ Node 1.1.3.1
And I got my data in json format and my code is following
var treeData = [];
var selKeys=[];
var key=0;
$(function(){
//alert(roleName);
$("#tree2").dynatree({
checkbox: true,
selectMode: 3,
children: treeData,
minExpandLevel: 2
});
$.ajax({
url: "http://localhost:8080/collection-ui/api/permissions/findall",
success: function( treeData ) {
var tree = $("#tree2").dynatree("getTree");
var rootNode = $("#tree2").dynatree("getRoot");
var TopRoot = rootNode.addChild({
title: 'Select All',
tooltip:'Select All'
});
$.each(treeData, function(key, val){
var ParentId = val['parentId'];
if(ParentId == 0)
{
key=val['permissionId'];
var childNode = TopRoot.addChild({
key: val['permissionId'],
title: val['permissionName'],
tooltip:val['permissionName']
});
}else{
var node = tree.getNodeByKey("ParentId");
node.addChild({
key: val['permissionId'],
title: val['permissionName']
tooltip:val['permissionName']
});
}
});
}
}) ;
But the else part in my code is not working properly.Is there any wrong ? When i run this program it shows like "node is null" Pls anybdy help...
You forgot a comma here
title: val['permissionName']
tooltip:val['permissionName']
Should be
title: val['permissionName'],
tooltip:val['permissionName']