@[Angular.forEach用法]
1.官方示例:
var values = {name: 'misko', gender: 'male'};
var log = [];
angular.forEach(values, function(value, key) {
this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: misko', 'gender: male']);
2.针对对象数组(key,value)
非官方示例:
var objs =[{a:1},{b:2}];
angular.forEach(objs, function(data,index,array){
//data等价于array[index]
//index 当前的索引
//array等价于objs
console.log(data.a+'='+array[index].a);
});
3.针对对象数组(data)
非官方示例:
var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data){
console.log(data.a);
});