如何在 ExtJs 中清除一棵树?
我已经成功创建了一个 Ext.tree .TreePanel 动态加载子节点,但我很难清除树并加载新数据。 有人可以帮我编写代码来执行此操作吗?
I have managed to create an Ext.tree.TreePanel that loads child nodes dynamically, but I'm having a difficult time clearing the tree and loading it with new data. Can someone help me with the code to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
来自 ExtJS 大师 Saki 的精彩博客。
http://blog .extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/
From the wonderful blog of Saki an ExtJS guru.
http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/
在Ext JS 4中:
如果要重新加载树面板的数据,则需要重新加载树存储:
其中treeId是树的id。 如果您有商店 id,则可以直接对商店 id 使用 load() 。
删除所有子节点:
但是,从存储中重新加载树节点时,不需要删除子节点。
In Ext JS 4:
if you want to reload the data of the tree panel, you need to reload the tree store:
where treeId is the id of the tree. If you have a store id, you may directly use load() on store id.
to remove all child nodes:
However, removing child nodes is not necessary for reloading the tree nodes from its store.
就我而言,我的 Ext 树有一个 AsyncTreeNode 类型的隐藏根节点。 如果我想清除树并从服务器重新填充,这非常简单:
In my case, my Ext tree has a hidden root node of type AsyncTreeNode. If I want to clear the tree and repopulate from the server, it's pretty simple:
我终于在他们的论坛中找到了答案。 对于任何感兴趣的人来说,它在这里:
I finally found an answer in their forums. For anyone interested it is here:
您可以简单地使用node.removeAll()来删除该节点的所有子节点。
http://docs.sencha. com/extjs/4.2.1/#!/api/Ext.data.NodeInterface-method-removeAll
you can simply use
node.removeAll()
to remove all child nodes from this node.http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.NodeInterface-method-removeAll
我遇到了类似的问题,我想出的解决方案是“标记”节点在折叠时尚未加载,从而在重新展开时强制重新加载。
I ran into a similar problem and the solution i came up with was to 'tag' the node has having not loaded when it was collapsed thus forcing a reload when it was re-expanded.
我不知道 Ext,但我猜他们有 DOM 抽象,这可能会让这件事变得更容易。 Prototype 中的等效项类似于:
除非
tree.root
引用集合对象而不是树的根 DOM 节点,但是否借用 DOM API 方法名称? 这似乎不太可能,特别是对于现代 JS 库而言。I don't know Ext, but I'm guessing that they have DOM abstraction that might make that easier. An equivalent in Prototype would be something like:
Unless
tree.root
refers to a collection object rather than the tree's root DOM node, but is borrowing DOM API method names? That seems really unlikely, especially for a modern JS library.