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);
  • 相关阅读:
    uniapp--悬浮可拖动按钮-实现思路
    js获取指定日期的前一天/后一天
    适配
    使用了@Slf4j log没有info的方法 .info()方法爆红或者log爆红
    用hexo在本地搭建自己的博客
    gulp 前端构建工具使用
    springboot+idea 热部署
    配置DNS服务器转发器
    windows server2008 r2安装DNS服务器
    卸载jdk1.7
  • 原文地址:https://www.cnblogs.com/miny-simp/p/9151417.html
Copyright © 2011-2022 走看看