zoukankan      html  css  js  c++  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);
    obj Object Array

    被迭代的对象.

    iterator Function

    迭代函数

    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
     
  • 相关阅读:
    八、springboot 简单优雅的通过docker-compose 构建
    【并发编程】ThreadLocal其实很简单
    计算机网络
    相似度
    不同激活函数的区别
    快速排序+归并排序
    xgboost
    c++面试
    PCA算法和SVD
    各种排序算法的时间复杂度和空间复杂度
  • 原文地址:https://www.cnblogs.com/zhx1991/p/4583523.html
Copyright © 2011-2022 走看看