Find a node within this tree using a string path or by attribute value(s). This method can be called with 1 or 2 arguments. If a single String argument is supplied, the value of the argument is treated as the path to the node. if a single argument of type Object is provided, it is treated as a set of field name/value pairs to search for (see {@link com.smartgwt.client..List#find}).
If 2 arguments are supplied, this method will treat the first argument as a fieldName, and return the first node encountered where
node[fieldName]
matches the second argument. So for example, given this tree:
foo zoo bar moo bar
Assuming your {@link com.smartgwt.client.widgets.tree.Tree#getPathDelim pathDelim}is the default
/
and
foo
is the name of the root node, then
tree.find("foo/moo/bar")
would return the
bar
node under the
moo
node.
tree.find("name", "bar")
would return the first
bar
node because it is the first one in the list whose
name
(default value of {@link com.smartgwt.client.widgets.tree.Tree#getNameProperty nameProperty}) property matches the value
bar
. The two argument usage is generally more interesting when your tree nodes have some custom unique property that you wish to search on. For example if your tree nodes had a unique field called "UID", their serialized form would look something like this:
{ name: "foo", children: [...], UID:"someUniqueId"}
You could then call
tree.find("UID", "someUniqueId")
to find that node. Note that the value doesn't have to be a string - it can be any valid JS value, but since this data generally comes from the server, the typical types are string, number, and boolean.
The usage where you pass a single object is interesting when your tree nodes have a number of custom properties that you want to search for in combination. Say your tree nodes had properties for "color" and "shape";
tree.find({color: "green", shape: "circle"}) would return the first node in the tree where both properties matched.
When searching by path, trailing path delimiters are ignored. So for example tree.find("foo/zoo/bar")
is equivalent to tree.find("foo/zoo/bar/")
@param fieldNameOrPath Either the path to the node to be found, or the name ofa field which should match the value passed as a second parameter
@return the node matching the supplied criteria or null if not found