How could i get the first node of a tree

i’ve got a xml tree,the follow is the xml:

<?xml version='1.0' encoding='UTF-8'?>


during the former edition i got the method : but it doesn’t work on the edition 3.0
dhtmlXTreeObject.prototype.getFirstNodeId =function()
{
var tempId = this.rootId;
var temp=this._globalIdStorageFind(tempId);
if(temp)return temp.childNodes[0].id;
else return “”;
};

who can help me thanks a lot

1 Like

and i am using ie9 and firefox 10.X

If you gave such simple Tree & you know its structure, use method ‘getItemIdByIndex(itemId,index)’

var tempId = this.rootId; var id = tree.getItemIdByIndex(tempId ,0);

Here is description:
docs.dhtmlx.com/doku.php?id=dhtm … midbyindex

thanks a lot but i’ve got null the follow is my code

function itemOnclick(id){
var url = “openUserWorkList.action?pd.id=”+id;
window.parent.frames[“mainIframe”].location.href=url;
}
function treeInit(){
tree=new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,0);
tree.setImagePath("<%=path%>/resource/dhtmlxTree/codebase/imgs/");
tree.enableCheckBoxes(0);
tree.setOnClickHandler(itemOnclick);
try{
var date = new Date();
tree.setXMLAutoLoading(“workDiaryProjectTreeXML.action?”+date.getTime());
tree.loadXML(“workDiaryProjectTreeXML.action”);
}catch(ex){
}
var tempId = tree.rootId;
var id = tree.getItemIdByIndex(tempId ,0);
alert(id);
}

</script>

You need to issue your getting of ID in a function :

function gettingID(){ var tempId = tree.rootId; var id = tree.getItemIdByIndex(tempId ,0); alert(id); }

And put it as the second parameter in loadXML() method:

tree.loadXML("workDiaryProjectTreeXML.action", gettingID);

In the other you can not get an item by its id as the item is not loaded yet.