我想创建两个链接:全部展开和全部折叠,用于处理aciTree中所有节点的打开和关闭。谁能帮我解决这个问题?我找到了为seleted节点打开的代码。但我需要它适用于所有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');
}
答案 0 :(得分:3)
您可以使用expand
和collapse
属性设置调用aciTree API,这样您就可以避免自己走遍整个树:
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
个事件)。