把新数组压入旧数组中

https://static.oschina.net/uploads/img/201705/22113755_ZiWi.png "

html:
   <div class="row" ng-repeat="model in goodsList">
            <div class="col-md-4" style="margin-top:5px">
                <!--<input type="checkbox" ng-model="model.checked">-->
                {{model.goodsName}}
                <!--<input type="checkbox" ng-model="model.checked">{{model.goodsName}}-->

            </div>
            <div class="col-md-3"  style="margin-top:5px">
                <!--<input type="checkbox" ng-model="model.checked">-->
                {{model.goodsId}}
                <!--<input type="checkbox" ng-model="model.checked">{{model.goodsName}}-->

            </div>
            <div class="col-md-3"  style="margin-top:5px;margin-left:40px;">
                <!--<input type="checkbox" ng-model="model.checked">-->
                {{model.amount}}
                <!--<input type="checkbox" ng-model="model.checked">{{model.goodsName}}-->

            </div>
            <div style="float:right;margin-top:-12px;margin-right:5px;margin-bottom:5px;">
                <button type="button" class="btn btn-default" ng-click="selectOne(model)">选择</button>
            </div>
        </div>

js:

 //点击选择时
     $scope.selectOne = function(model){

    // $scope.model = model;
    // console.log($scope.model);
    var check = true;//声明一个全局变量为true的时候就添加
    angular.forEach($scope.mod_configList,function(data,index){

        if(data.amount == model.amount){//比较两组数组中的这个变量是不是相同,如果相同的话就声明的变量就为false
            check=false;
            swal("该面值的商品已存在");
            return;
        }
        if(data.goodsId == model.goodsId){

            check=false;
            swal("该商品的ID已存在");
            return;
        }
    });

    if(!check){

        return;
    }
    //点击选择时把选择的卡加入到一个数组中
    var tmp = new Object();//new一个新对象
    tmp.goodsName = model.goodsName;
    tmp.goodsId = model.goodsId;
    tmp.amount = model.amount;
    $scope.mod_configList.push(tmp);
    console.log(tmp);

};

转载于:https://my.oschina.net/pingheyongfeng/blog/906520

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值