文章转载于: Ext.each的用法 http://www.studyofnet.com/news/152.html
语法:
each( Array/NodeList/Mixed array, Function fn, Object scope)
Ext.each 的用法与 JQuery.each 类似,不同之处在于Ext.each的第三个参数可以指定回调函数的执行上下文。
Extjs中对Ext.each的定义的源码:
each : function(array, fn, scope){
if(Ext.isEmpty(array, true)){
return;
}
if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
array = [array];
}
for(var i = 0, len = array.length; i < len; i++){
if(fn.call(scope || array[i], array[i], i, array) === false){//3等号
return i;
};
}
}
关于 Ext.each的几个实例:
var people = ['Bill', 'Saul', 'Gaius'];
//using each to detect Cylons:
var f=function (person, index)
{
var cylon = (index + 1) % 2 == 0; //every second man is a toaster
alert(person + (cylon ? ' is ' : ' is not ') + 'a fraking cylon');
}
Ext.each(people,f);
//JS数组
Ext.each([1,0,3,4,5,6,8],function(item){alert(item)});
//JS数组里JSON对象
Ext.each([{name:"cola",age:27},{name:"moka",age:28}],function(item){alert(item.name)});