Angular.forEach用法

1.针对对象循环(key,value)angularjs

官方示例:数组

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)this

非官方示例:spa

var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data,index,array){
//data等价于array[index]
console.log(data.a+'='+array[index].a);
});

3.针对对象数组(data)code

非官方示例:对象

var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data){
console.log(data.a);
});

 

参数:blog

Param Type Details
obj ObjectArray

Object to iterate over.get

iterator Function

Iterator function.input

context
(optional)
Object

Object to become context (this) for the iterator function.it

相关文章
相关标签/搜索