先前的有一点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>