0

我想创建两个链接:全部展开和全部折叠,用于处理 aciTree 中所有节点的打开和关闭。谁能帮我解决这个问题?我找到了为选定节点打开的代码。但我需要它用于所有 inode。这是代码

var api = $('#indvTree').aciTree('api');
var selectedItem = api.selected();
        if (api.isInode(selectedItem)) {
            // this is a tree inode
            if (api.isOpen(selectedItem)) {
                // if already opened
                alert('you need to select a closed inner node\nthe current one is already open');
            } else {
                // open the inner item
                api.open(selectedItem, {
                    uid: 'my-custom-button',
                    success: function(item, options) {
                        var itemId = this.getId(item);
                        alert('a item was just opened, the item ID was ' + itemId);
                    },
                    fail: function(item, options) {
                        var itemId = this.getId(item);
                        alert('failed to open the item with the ID ' + itemId);
                    },
                    _custom_property: 'some-custom-value'
                });
            }
        } else {
            // no selected item or not a tree inode item
            alert('you need to select a closed inner node first');
        }
4

1 回答 1

3

expand您可以使用设置和属性调用 aciTree API,collapse这样您就可以避免自己遍历整个树,这样:

var openAll = function() {
    var rootChildren = api.children(null);
    var inodes = api.inodes(rootChildren);
    inodes.each(function() {
        // open this node
        api.open($(this), {
            expand: true // to open his childrens too
        });
    });
};

var closeAll = function() {
    var rootChildren = api.children(null);
    var inodes = api.inodes(rootChildren);
    inodes.each(function() {
        // open this node
        api.close($(this), {
            collapse: true // to close his childrens too
        });
    });
};

其中api是您通过调用获得的全局变量aciTree('api')(如您的代码中所示)。

然后调用openAll打开所有树节点并将closeAll它们全部关闭(处理onclick链接上的事件)。

于 2014-08-11T09:15:32.277 回答