jay@moduscreate.com
1 Oct 2008, 6:39 AM
/**
* Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
* function call will be the scope provided or the current node. The arguments to the function
* will be the args provided or the current node. If the function returns false at any point,
* the bubble is stopped.
* @param {Function} fn The function to call
* @param {Object} scope (optional) The scope of the function (defaults to current node)
* @param {Array} args (optional) The args to call the function with (default to passing the current node)
*/
Ext.override(Ext.data.Node, {
bubble : function(fn, scope, args){
var p = this;
while(p){
var returnVal = fn.apply(scope || p, args || [p]);
if(returnVal === false ){
break;
}
else if (returnVal) {
return(returnVal);
}
p = p.parentNode;
}
}
});
usage :
var obj = node.bubble(function(treeNode) {
if (treeNode.attributes.someAttribute == 'someVal') {
return({
someAttr : treeNode.attributes.text,
anotherAttr : treeNode.parentNode.attributes.text
});
}
});
* Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
* function call will be the scope provided or the current node. The arguments to the function
* will be the args provided or the current node. If the function returns false at any point,
* the bubble is stopped.
* @param {Function} fn The function to call
* @param {Object} scope (optional) The scope of the function (defaults to current node)
* @param {Array} args (optional) The args to call the function with (default to passing the current node)
*/
Ext.override(Ext.data.Node, {
bubble : function(fn, scope, args){
var p = this;
while(p){
var returnVal = fn.apply(scope || p, args || [p]);
if(returnVal === false ){
break;
}
else if (returnVal) {
return(returnVal);
}
p = p.parentNode;
}
}
});
usage :
var obj = node.bubble(function(treeNode) {
if (treeNode.attributes.someAttribute == 'someVal') {
return({
someAttr : treeNode.attributes.text,
anotherAttr : treeNode.parentNode.attributes.text
});
}
});