cgoss
28 Jun 2007, 11:42 AM
Thought I'd share this helpful function that Yahoo supports in their tree that I've adapted for use in Ext.
/**
* Returns a node that has a matching property and value in the data
* object that was passed into its constructor.
* @method getNodeByProperty
* @param {object} property the property to search (usually a string)
* @param {object} value the value we want to find (usuall an int or string)
* @return {Node} the matching node, null if no match
*/
Ext.data.Tree.prototype.getNodeByProperty = function(property, value) {
for (var i in this.nodeHash) {
var n = this.nodeHash[i];
if (n.attributes && value == n.attributes[property]) {
return n;
}
}
return null;
};
Usage:
var node = tree.getNodeByProperty('uniqueId','unique_'+someId);
/**
* Returns a node that has a matching property and value in the data
* object that was passed into its constructor.
* @method getNodeByProperty
* @param {object} property the property to search (usually a string)
* @param {object} value the value we want to find (usuall an int or string)
* @return {Node} the matching node, null if no match
*/
Ext.data.Tree.prototype.getNodeByProperty = function(property, value) {
for (var i in this.nodeHash) {
var n = this.nodeHash[i];
if (n.attributes && value == n.attributes[property]) {
return n;
}
}
return null;
};
Usage:
var node = tree.getNodeByProperty('uniqueId','unique_'+someId);