I’m trying to get the nodes using depth. I’m getting all the values from a database and the values are all unique and correct. So, when I’m at the very first node, i.e. when depth is 0, the nodes are being displayed correctly but when I try to start from any other node, there is nothing being displayed. I tried alerting the insertNewchild to see what value it is getting. When it is at the first node, it alerts object object but at any other node it alerts -1. When I debug the code, all the other values are being taken in correctly. Please help me.
function populateTree(xml)
{
var xmlDoc = parseXMLText(xml);
var root = xmlDoc.documentElement;
var userTree = new Array();
if(root.nodeName == ‘AdvertisementTree’)
{
userTree = xmlListToArray(root, ‘id’);
}
var treeNodesCount = userTree.length;
tree.deleteChildItems(0);
for(var i = 0; i < treeNodesCount; i++)
{
var treeNode = userTree[i];
var type = treeNode[‘Type’];
if(type === ‘group’)
{
var id = parseInt(treeNode[‘id’], 10);
if(id > maxID)
maxID = id;
alert(tree.insertNewChild(treeNode[‘ParentID’], id, treeNode[‘Name’], 0, ‘folderClosed.gif’));
tree.setUserData(id, ‘nodename’, treeNode[‘Name’]);
tree.setUserData(id, ‘type’, type);
}
else if(type === ‘advertisement’)
{
var id = parseInt(treeNode[‘id’], 10);
if(id > maxID)
maxID = id;
tree.insertNewChild(treeNode[‘ParentID’], id, treeNode[‘Name’], 0, ‘advertisement.png’);
tree.setUserData(id, ‘nodename’, treeNode[‘Name’]);
tree.setUserData(id, ‘type’, type);
tree.setUserData(id, ‘playlistid’, treeNode[‘PlaylistID’]);
}
}
}