【发布时间】:2015-05-01 00:22:05
【问题描述】:
当我检查“主”复选框时,我想要实现的是检查属于 ng-repeat 循环迭代的一些复选框。到目前为止我的代码在视图中:
<div ng-app="CheckAllModule">
<div ng-controller="checkboxController">
<ul ng-repeat="s in struct">
<li><strong>{{s}} item</strong>
<input type="checkbox" ng-checked="x1 && x2 && x3" ng-model="selectedAll" ng-click="checkAll()" />
</li>
<label>Subitem A
<input type="checkbox" ng-checked="chk" ng-model="x1" />
</label>
<label>Subitem B
<input type="checkbox" ng-checked="chk" ng-model="x2" />
</label>
<label>Subitem C
<input type="checkbox" ng-checked="chk" ng-model="x3" />
</label>
</ul>
</div>
</div>
第一个复选框是“主人”,应该将自己的状态强加给“奴隶”(接下来的三个复选框),无论它们之前的状态是什么。
关于从属复选框,它们应该被单独选中和取消选中。但是如果三者同时查的话,高手应该也是。每当只检查其中一个时,主人不应该也是如此。
还有我的控制器:
var app = angular.module("CheckAllModule", []);
app.controller("checkboxController", function ($scope) {
$scope.struct = ['First', 'Second'];
$scope.checkAll = function () {
if ($scope.selectedAll) {
$scope.chk = true;
} else {
$scope.chk = false;
}
};
});
【问题讨论】:
标签: javascript angularjs checkbox