Google Closure Library - 将非 TreeNode 子级添加到 TreeNode
我特别使用 Google Closure Library 和 goog.ui.tree 来构建树形结构 GUI 组件。它开箱即用,效果很好,但我想为每个叶子添加一些额外的控件(特别是 goog.ui.Checkboxes)。
问题在于 Component.addChild 已在 BaseNode 中被重写,因此每个添加的子项都被视为子树节点,而不是子组件。实际上,如果您尝试添加除实际树节点之外的任何其他内容作为子节点,则会引发大量错误,因为会遍历这些子节点并对它们调用特定于 BaseNode 的函数。
我必须承认我是一个 Closure 新手,但我认为必须有一些解决方法,对吗?本质上,我想做的就是在树中的每片叶子旁边出现一堆复选框。
谢谢, 安德烈亚斯
I'm using the Google Closure Library and goog.ui.tree in particular to build a tree structure GUI component. It works pretty well out of the box, but I'd like to add a few extra controls to each of the leaves (goog.ui.Checkboxes in particular).
The problem is that Component.addChild has been overridden in BaseNode so that each added child is treated as a child tree node as opposed to a child component. In effect plenty of errors are thrown if you try to add anything else than an actual tree node as a child, as these children are traversed and BaseNode-specific functions are called on them.
I must admit I'm quite a Closure newb, but I reckon there must be some workaround for this, right? Essentially all I want to do is have a bunch of checkboxes appear next to each leaf in my tree.
Thanks,
Andreas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了我对您的问题留下的更一般性评论之外,我在 goog.ui.tree.BaseNode 上发现了以下属性,可以满足简单的需求:
可以使用以下方式设置:
In addition to the more general comment I left on your question, I found the following property on goog.ui.tree.BaseNode that may work for simple needs:
This can be set using:
看起来 TreeNode 父类实现 - goog.ui.tree.BaseNode - 违反了与祖先类 Component 相关的一些约定。
很明显,goog.ui.tree.BaseNode.addChildAt 方法重写更改了父规范,因为它忽略了 render 布尔属性。
解决方法是通过展开您立即需要使用的树节点来强制渲染。之后您可以再次折叠它们。
这个组件的实现有点糟糕。
Looks like the TreeNode parent class implementation - goog.ui.tree.BaseNode - has violated some contract related to the ancestor class Component.
It is clear that goog.ui.tree.BaseNode.addChildAt method override changed the parent specification since it ignores the render boolean attribute.
The work around is to force the rendering by expanding the tree nodes that you need immediately for use. After you can collapse them again.
Implementation is a little bit crappy for this component.