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 true. * @param {Function} fn A function which must return true if the passed Node is the required Node. * @param {Object} scope (optional) The scope (this 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之中找不到,希望大家能够互相分享下。