我有一个延迟加载 dijit.tree,我想在加载数据后在很多地方重用它。但是,如果我只是用包含最多数据的树替换其他树中的存储对象,那么节点就会全部展开。我想修改商店,以便在将其设置为新树中的商店之前折叠所有项目。你能告诉我如何实现这一目标吗?
最佳答案
您不能为此使用存储,因为它不包含树节点状态的任何信息。这种“魔法”是通过 TreeNode
执行的,参见一些examples here
“完美的解决方案”是找出需要扩展的路径,然后设置树的路径以遍历到所需的树节点。
但是,由于您的延迟加载,您需要检查 state
- 初始化树时它应该是 UNCHECKED
。然而,内置的 cookie 功能可能正在发挥作用,请确保使用 { persist:false }
创建新树。
您还可以扩展您的树,以便它接受 collapseChildren(TreeNode)
如下-然后调用tree.set("path", [pathsArray]);
collapseChildren : function(top) {
var self = this;
if(!top || !self.model.mayHaveChildren(top.item)) return;
top.getChildren().forEach(function(n) {
if(n.item.children) {
//dojo.style(n.getParent().containerNode, { overflowY: 'hidden', overflowX: 'hidden'});
self._collapseNode(n);
self.collapseChildren(n);
}
});
},
编辑:
If the autoExpand flag is passed to the constructor, the Tree is initially shown with all nodes expanded.
You can then call collapseAll() and expandAll() to collapse and expand the Tree, respectively. http://livedocs.dojotoolkit.org/dijit/Tree-examples#id3
关于javascript - dijit.tree 如何仅使用存储来实现折叠所有功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10732719/