Paul
Paul

Reputation: 3880

How to find if a TreeNode has children

I was using the com.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 the com.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...

Upvotes: 1

Views: 5335

Answers (2)

Mike Lentini
Mike Lentini

Reputation: 1358

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 use getChildren(TreeNode node) to get the array of children and then get the size of the array.

Upvotes: 3

Aaron McIver
Aaron McIver

Reputation: 24713

Looks like you can use...

getChildren(TreeNode node)

As viewed in the source

Upvotes: 1

Related Questions