Dynatree仅展开树的最后一个节点

Dynatree expand only the last node of tree

本文关键字:最后一个 节点 Dynatree      更新时间:2024-06-24

我使用Dynatree来获得树视图,现在我想展开/折叠所有节点,但只有树的最后一个节点展开。

你可以在小提琴上看到这种效果:http://jsfiddle.net/aA76N/2/

以下是我用来展开/折叠节点的代码。

$('.panel-heading').on('click', '.expand-all', function() {
    $('#tree-team').dynatree('getRoot').visit(function(node) {
        node.expand(true);
    });
    $(this).children().removeClass('glyphicon-folder-open').addClass('glyphicon-folder-close');
    $(this).removeClass('expand-all').addClass('collapse-all');
    return false;
});
$('.panel-heading').on('click', '.collapse-all', function() {
    $('#tree-team').dynatree('getRoot').visit(function(node) {
        node.expand(false);
    });
    $(this).children().removeClass('glyphicon-folder-close').addClass('glyphicon-folder-open');
    $(this).removeClass('collapse-all').addClass('expand-all');
    return false;
});

autoCollapse选项正在扰乱展开/折叠。只要评论一下就行了。

http://jsfiddle.net/aA76N/4/

$('#tree-team').dynatree({
    //autoCollapse: true,
    ...
});