ext js findChild

最近做了一个程序模块,根据一棵树查找树节点,树的id是js自己生成的,所以我就选用其他方式来查找树节点
var node = TreePanel.root.findChild( String attribute, Mixed value ) ;
但是我调用了方法之后 火狐一直报错 node为null;
后来安装了spket之后 翻看源代码
findChild : function(attribute, value, deep){
return this.findChildBy(function(){
return this.attributes[attribute] == value;
}, null, deep);
},

/**
* Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
* @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
* @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
* @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
* @return {Node} The found child or null if none was found
*/
findChildBy : function(fn, scope, deep){
var cs = this.childNodes,
len = cs.length,
i = 0,
n,
res;
for(; i < len; i++){
n = cs[i];
if(fn.call(scope || n, n) === true){
return n;
}else if (deep){
res = n.findChildBy(fn, scope, deep);
if(res != null){
return res;
}
}

}
return null;
},



findChild : function(attribute, value, deep){

原来还隐含了一个参数deep ,默认为false 只查找到他的子节点,
把他设为true 可以查找到root下的所有子孙节点。
findChild('pid',123,true);

总结:API要尽量与自己用的开发版本相匹配,ext中还有很多函数可用却在api之中找不到,希望大家能够互相分享下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值