我有一个复选框+标签列表。如果您检查第一个,则必须禁用所有复选框(第一个除外)。问题是,如果我取消选中第一个复选框,则所有其他复选框仍处于禁用状态,我希望它们再次启用。
JS
<li ng-repeat="ques in questions">
<input type="checkbox" ng-click="addRemove(ques)" ng-checked="contains(ques) != -1" ng-disabled="noneSelected && $index != 0"/> {{ques.question}}
</li>
控制器
if (ques.question == "None") {
var index = $scope.contains(ques);
if (index != -1) {
$scope.noneSelected = false;
$rootScope.selectedQuestions.splice(index, 1);
} else {
$scope.noneSelected = true;
$rootScope.selectedQuestions = [];
$rootScope.selectedQuestions.push(ques);
}
}
解
在其余的代码中,我在selectedQuestions
数组上做了一些sutff。这引起了一些麻烦。
答案 0 :(得分:3)
我看不到你的其他代码,但请看下面的演示:
var app = angular.module('app', []);
angular.module('app').controller('homeCtrl', homeCtrl);
homeCtrl.inject = ['$scope']
function homeCtrl($scope) {
$scope.questions = [{
question: "what"
}, {
question: "when"
}, {
question: "who"
}]
};
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-controller="homeCtrl">
<li ng-repeat="ques in questions">
<input type="checkbox" ng-disabled="questions[0].val && $index>0" ng-model="ques.val" />{{ques.question}} {{question.val}}
</li>
</body>
</html>