已选择过的酒品品种,第二次选择时,会提示选择重复---改进

先前的有一点bug,如此写后更简单

js代码

 

    
//已选择的品种,不能再次选择
   
    var selectList =[];
    $scope.selectGoods=function(item,index){
    	if(selectList.length>0){
    		var flag=0;
    		for(var i=0;i<selectList.length;i++){
    			if(selectList[i]==item&&item!=undefined){
        			$scope.result = {};
        	        $scope.result.title = "提示消息";
        	        $scope.result.msg = "亲,请不要选择重复商品!";
        	        $scope.popup();
        			//对当前的所选择的进行清空
        			$scope.applyList.purchaseLists[this.$index]={};
        			flag=1;
        		}
        	}
    	}else if(flag==1){
    		selectList[index]=null;
    	}else{
    		selectList[index]=item;
    	}
    };
    
  //添加列表
    $scope.addCols = function(){
        $scope.applyList.purchaseLists.push({});
    };
  //删除列表
    $scope.removeRow = function(index,item){	
        $scope.applyList.purchaseLists.splice(index, 1);
    	selectList.splice(index,1);
    };
    
  //弹窗开始
    $scope.popup = function() {
        $modal.open({
            templateUrl : 'tpls/common/alertMessage.html',//弹窗公共页面
            controller :ModalInstanceCtrl2,
            resolve : {
                requestResults : function() {
                    return $scope.result;
                }
            }
        }); 
    };
    var ModalInstanceCtrl2 = function($scope, $modalInstance, requestResults) {
        $scope.results = requestResults;
        // 确认按钮(close()可以带参数)
        $scope.ok = function() {
            $modalInstance.close();
        };
    };
    //弹窗结束

html部分代码:
 

 

 

<tr name="form" ng-repeat="item in applyList.purchaseLists">
    <td>
        <select ng-model="item.goods" name="goods" ng-options="product.goodsName for product in products" ng-required="true" ng-change="selectGoods(item.goods,$index)">
            <option value="">请选择品种</option>
        </select>
    </td>

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值