| obj | ObjectArray |
被迭代的对象. |
| iterator | Function |
迭代函数 |
| context
(optional)
|
Object |
Object to become context ( |
<!DOCTYPE HTML>
<html ng-app="elementExample">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="angular.min.js"></script>
</head>
<body>
<div id="test">博弈网络科技</div>
<div>
angular.forEach(obj, iterator, context)
<input type="button" onclick="button1()" value="比较值"></input>
</div>
<hr>
<div>
angular.forEach(obj, iterator)
<input type="button" onclick="button2()" value="比较值"></input>
</div>
<br>
<script>
function button1(){
var values = {name: ‘misko‘, gender: ‘male‘};
var log = [];
angular.forEach(values, function(value, key) {
this.push(key + ‘: ‘ + value);
}, log);
alert(log);
}
function button2(){
var values = {name: ‘misko‘, gender: ‘male‘};
var log = [];
angular.forEach(values, function(value, key) {
log.push(key + ‘: ‘ + value);
});
alert(log);
}
</script>
</body>
</html>
?原文:http://boyitech.iteye.com/blog/2166634