Dynatree Expand Parents of Selected Nodes

2019-05-07 14:27发布

问题:

I have Dynatree running well on my page. I am using an initAjax to get the structure. When I generate my json I include "select": true where appropriate to select check-boxes. Most (all) of the check-boxes are at a depth of three levels down from the root.

I would like to expand the parents of the selected nodes so the user can see the selected check-boxes when the page loads.

I think I need to do something on the onPostInit function with getSelectedNodes, but I can not nail down the code?? I'm not sure if I should be using a each statement to loop through the selected nodes? Any help would be greatly appreciated!

--UPDATE--

I figured it out!!

onPostInit: function(isReloading, isError) {
            var tree = $('#tree').dynatree('getTree');
            var selKeys = $.map(tree.getSelectedNodes(), function(node){
                node.makeVisible();
            });
         }

回答1:

Slightly shorter response:

onPostInit: function() {
    $.map(this.getSelectedNodes(), function(node){
        node.makeVisible();
    });
}