我想创建两个链接:Expand All和Collapse All,它们处理aciTree中所有节点的打开和关闭。有人能帮我解决这个问题吗?我已经找到了为选定节点打开的代码。但所有节点都需要它。下面是代码
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 nodenthe 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');
}
你可以调用带有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
事件在您的链接)。