tags:

views:

73

answers:

2

Hi all

I'm trying to check whether a certain node exists beneath a branch of an ExtJS tree. Knowing the ID of the parent node, is there a library function to check whether a node exists beneath the parent (by its ID)?

I've checked the API numerous times over, and can only seem to accomplish this by iterating through the entire branch of the tree.

Is there a library function which allows me to check if a child exists (by its ID) if the parent node ID is known?

Thanks!

PS, to find the parent ID, I'm using the following:

tree.getNodeById('myID');
+1  A: 

Have you looked at DomQuery? The API defines the method jsSelect: selects a group of elements.

jsSelect( String selector, [Node/String root] ) : Array

Parameters:

selector : String The selector/xpath query (can be a comma separated list of selectors) root : Node/String (optional) The start of the query (defaults to document).

Returns an Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.

Upper Stage
Ta for this, I wasn't aware of DomQuery and it'll certainly come in handy elsewhere.
Alan Grant
+3  A: 

Ext.tree.TreeNode "contains" function does exactly what you want:

var parent = tree.getNodeById('myID');
parent.contains(tree.getNodeById('childId'));
ncardeli
Jackpot. Ta v.much.
Alan Grant