How to preselect nodes using jsTree jQuery plug-in

Posted by Ed Schembor on Stack Overflow See other posts from Stack Overflow or by Ed Schembor
Published on 2010-03-11T04:32:53Z Indexed on 2010/03/11 4:39 UTC
Read the original article Hit count: 485

Filed under:
|
|

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:

    $(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() } }
            }
        }
    )

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-plugins