I am using the jsTree jQuery plug-in with its “Checkbox” plug-in and using an async http request to lazy-load each level of the tree. All works great, except that I cannot get the tree to pre-select certain nodes after the first level. I am using the “selected” attribute to provide an array of ID’s to preselect. ID’s in the top level of the tree are correctly pre-selected. However, ID’s in lower levels of the tree are not selected when the level loads. Am I missing something?
Here is the constructor code:
var myArrayOfIDs = new Array();
myArrayOfIDs[0] = '123'; //etc...
$(sDivID).tree(
{
data : {
async : true,
opts : {url : sURL}
},
plugins:{
"checkbox" : {three_state : false}
},
selected : myArrayOfIDs,
ui:{
theme_name : "checkbox",
dots : false,
animation : 400
},
callback : {
beforedata : function(NODE, TREE_OBJ) { return { id : $(NODE).attr("id") || 0, rand : Math.random().toString() } }
}
}
)
Hmm, your code looks fine to me.
I took a slightly different approach in my solution because I wanted the server i.e. your sURL to tell me which items should be selected – then in jsTree’s onload callback I select them.
Update: I’ve updated my jsTree blog post to the latest version of jsTree here
-Matt