如何查找 TreeNode 是否有子节点
我当时用的是 com.google.gwt.user.client.ui.Tree
小部件,对于选定的TreeItem
,我可以轻松检查它是否有任何子项:
Tree nodesTree = new Tree();
nodesTree.getSelectedItem().getChildCount()
现在我想使用 com.smartgwt.client.widgets.tree.Tree
小部件,但我不知道如何查找选定的 TreeNode
是否有任何子节点。我对此有点困惑...
I was using thecom.google.gwt.user.client.ui.Tree
widget where for a selectedTreeItem
I could easily check if it has any children:
Tree nodesTree = new Tree();
nodesTree.getSelectedItem().getChildCount()
Now I wanted to use thecom.smartgwt.client.widgets.tree.Tree
widget but I do not know how to find if a selected TreeNode
has any children. I'm a little confused on this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速谷歌一下,它是
hasChildren(TreeNode node)
,它返回一个布尔值。请参阅这里。编辑:这检查节点是否有任何子节点(显然)。如果你想真正得到孩子,请参阅下面亚伦的回答。
getChildren(TreeNode node)
返回树节点数组。因此,如果您想查看它有多少个子节点,可以使用 getChildren(TreeNode node) 来获取子节点数组,然后获取数组的大小。A quick google says it's
hasChildren(TreeNode node)
, which returns a boolean. See here.EDIT: This checks if the node has any children (obviously). If you want to actually get the children, see Aaron's answer below.
getChildren(TreeNode node)
returns an array of tree nodes. So if you wanted to see how many children it has, perhaps usegetChildren(TreeNode node)
to get the array of children and then get the size of the array.看起来您可以使用...
如 来源
Looks like you can use...
As viewed in the source