[jQuery] ajax TreeView recursive open

[jQuery] ajax TreeView recursive open


Hello,
I'm using a Treeview plugin (http://docs.jquery.com/Plugins/Treeview)
with its async extension.
Basic usage is very well working, I just had to change a bit the async
code to suit my needs.
Actually, I'm trying to recursively open given nodes ; but without
success...
I got an ajax result, like {"node-10", "node-50", "node-165",
"node-351"} for, say, "node-2" (which is part of the first loaded
three). What I want to do is : add children for node-2, in these results
I'll have a node-10, add children for it, which will contains node-50
and so on, until I I found "node-351" that will just be marked as
'selected' and should not open.
My code looks like this :
$.getJSON(_href, function(response) {
var _node = null;
$.each(response, function(){
var _full_current = this.toString();
var _current =
_full_current.substring(_full_current.indexOf('-')+1, _full_current.length);
_node = $("#explorer li[id$='"+_current+"']");
if(_node.length == 1){ //only if a node has been found found
if( _node.find('li[id!=placeholder]').length == 0 )
//check if node is not already open
_node.treeview({
url: 'tdm-'+_full_current+'.json'
});
}
});
//we now want to put 'selected' class on the current element
_node.find('#' + _id).addClass('selected');
});
With these code, for the above example, I had to repeat the action four
times :-/ Code works well, but I think that first asked node is not yet
loaded when it tries to load the second.
I do not know how to wait for the node is properly loaded to load the
next one.
Maybe is there a better way to do this, I do not know...
Any help or hint would be appreciated :)
Regards,
Johan