星空网 > 软件开发 > Java

AngularJS之forEach

angular.forEach
描述:
    循环对obj对象的每个元素调用iterator, obj对象可以是一个Object或一个Array. Iterator函数调用方法: iterator(value, key, obj), 其中obj是被迭代对象,key是obj的property key或者是数组的index,value就是相应的值啦. (此函数不能够迭代继承的属性.)
使用方法:
    angular.forEach(obj, iterator, [context])
参数详解:
    Param Type Details
    angular.forEach(obj, function(value,index,objs){}, context);
objObject Array

被迭代的对象.

iteratorFunction

迭代函数

context(optional)
Object

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

 
 
 
 
 
 
 
返回值:
    对obj的引用
 
  var heros = [{      "hero" : "曙光女神",      "role" : "sup",      "line" : "不管刮风还是下雨,太阳照常升起"}],    context = document.getElementById('context'),    arr = [];    angular.forEach(heros,function(hero,index,objs){      //value === objs[index]      angular.forEach(hero,function(value,index){        this.push(index+"-"+value);      },arr);    });    context.innetText?context.innetText = arr.join(''):context.textContent = arr.join('');

 
效果:
    http://runjs.cn/detail/ixfp2ics

 





原标题:AngularJS之forEach

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Myer Market:https://www.ikjzd.com/w/1573202927708528642
MyFatoorah:https://www.ikjzd.com/w/1573202928874201090
MyGlamm:https://www.ikjzd.com/w/1573202929532706818
美宏联运:https://www.ikjzd.com/w/1573202930107670530
麦萌健康:https://www.ikjzd.com/w/1573202931047194625
International Bridge:https://www.ikjzd.com/w/1573202931646636033
石象湖景区门票-石象湖景区门票优惠政策:https://www.vstour.cn/a/411243.html
北京到嵩山自驾游沿途景点 北京距离嵩山有多远:https://www.vstour.cn/a/411244.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流