zoukankan      html  css  js  c++  java
  • angular.forEach()

    angular.forEach()

    forEach迭代对象或者数组。

    example:

    var values = {name: 'misko', gender: 'male'};
    var log = [];
    var tmpVal = angular.forEach(values, function(value, key, obj) { 
      this.push(key + ': ' + value);
    }, log);
    console.log(values);
    console.log(log);
    console.log(tmpVal);

    result:

    Object {name: "misko", gender: "male"}//values
    ["name: misko", "gender: male"]//log
    Object {name: "misko", gender: "male"}//tmpVal

    angularjs的for循环中,如果访问后台接口,需要对返回值判断,这时候就会出现异步加载的问题。

    用angular.forEach() 解决这个问题,代码如下(value为 $scope.uploadDataList 中的值,index 是数组的索引值):

    angular.forEach($scope.uploadDataList, function(value,index){
        $scope.uploadData = value;
        $scope.uploadData.name = $scope.IPSUser.name;
        $scope.uploadData.part = inds;
        $http.post($scope.URL+"zhuanlistatus/addZhuanliStatus",$scope.uploadData).success(function(data) {
            if(data.result){
                if(index == $scope.uploadDataList.length-1) {
                    layer.alert("通知书添加成功",{time:2000});
                    ngDialog.closeAll();
                }
            }else{
                $scope.falseList.push(value);
                ngDialog.closeAll();
                if(index == $scope.uploadDataList.length-1) {
                    ngDialog.open({
                        template: 'html/maintain/falseListPage.html',
                        className: 'ngdialog-theme-plain',
                         '40%',
                        scope: $scope,
                        cache: false
                    });
                }
            }
        });
    },$scope.falseList);
  • 相关阅读:
    「Poetize10」封印一击
    「Poetize10」能量获取
    vijosP1499炸毁燃料库
    BZOJ3550: [ONTAK2010]Vacation
    总结#3--一类最小割问题
    BZOJ1976: [BeiJing2010组队]能量魔方 Cube
    BZOJ2132: 圈地计划
    BZOJ2127: happiness
    BZOJ1754: [Usaco2005 qua]Bull Math
    920. 会议室
  • 原文地址:https://www.cnblogs.com/miny-simp/p/9151417.html
Copyright © 2011-2022 走看看