setColor for Tree Node

Hi there,

got one problem with dhtmlx Tree setItemColor(itemId, defaultColor, selectedColor)…
It works fine when I use onClick event (with getSelectedItemId()) but my requirement is to make it work dynamically(when the data is populated in to tree).

I Have a Load xml statements like this…

tree1.setXMLAutoLoading(“example1.jsp?ex=X&tooltips=true”);
tree1.loadXML(“example2.jsp?ex=X&tooltips=true”, loadOpenStates);

so while populating the data in to tree, I just want to check …

if(node == something){
tree1.setItemColor(itemId, defaultColor, selectedColor); // change colour
}else{
// leave as is…
}

How can I do this?
many thanks

Data loading is async. , you need to call you code not directly after load XML but from callback

tree1.loadXML("example2.jsp?ex=X&tooltips=true", function(){ //code which changes colors of items, need to be placed here });

ohh that was quick thanks.

tried it as you mentioned but my requirement is…

tree1.setXMLAutoLoading(“example1.jsp?ex=X&tooltips=true”,function(){
tree1.setItemColor(getSelectedItemId(), ‘#C8C8C8’,’#C8C8C8’ );// didn’t work
// Here I need something like forEach()
// I need to check every item to display colour accordingly…
});

Thanks

tree1.attachEvent("onXLE", function(){ var id = tree.getSelectedItemId(); if (id) tree1.setItemColor(id, '#C8C8C8','#C8C8C8' ); })

Now code will be triggered after each data loading