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);
};