Search code examples
jquerydynatree

Expand All Nodes on Lazyload in Jquery dynatree


I am using Dyna Tree plugin for tree view.

Now, while expanding the parent node I am using lazy load function,

onLazyRead: function(node){
    node.appendAjax({
    url: TREEVIEW_JSON_URL
    });
}

Now I would like to expand all the child and sub-child nodes those are available in my response with lazyLoad. In the current scenario I am able to expand only child nodes.

Please help me out on this. Thanks in advance


Solution

  • You could try something like this (haven't tested it though):

    $("#tree").dynatree({
        […]
        onLazyRead: function(node){
            node.appendAjax({url: TREEVIEW_JSON_URL,
                             success: function(node) {
                                 // Called after nodes have been created and the waiting icon was removed.
                                 // now expand all children
                                 node.visit(function(n){
                                     n.expand(true);
                                     });
                                 }
                             });
        },
        […]
    });