【发布时间】:2015-01-24 17:34:00
【问题描述】:
大家好我在使用嵌套复选框时遇到了一些问题。在我的问题中,我坚持如何在单击复选框上使用 IncludeAll。如果复选框值为真,那么它会给我一个值。如果 IncludeAll 复选框为真,则所有复选框将被选中并显示 Array 中的所有值。如果其中一个复选框为 false,则 IncludeAll 复选框为 false..但如果另一个复选框将被选中。
这是我的小提琴链接: http://jsfiddle.net/0x4396pu/1/
这是我的 Html 代码:
<form action="#" ng-controller='MyCtrl'>
<div class="control-group" ng-repeat="story in stories">
<br>
<input type="checkbox" ng-model="story.selectionAll">
<label class="control-label">IncludeAll {{story}}</label>
<div class="controls">
<label class="checkbox inline" ng-repeat="browser in browsers">
<input type="checkbox" value="{{browser}}"
ng-model="selection[story].browsers[browser]"
ng-checked="story.selectionAll">
{{browser}}
</label>
</div>
</div>
</div>
<pre>{{selection | json }}</pre>
</form>
这是我的控制器文件:
function MyCtrl($scope) {
$scope.stories = ['1', '2', '3'];
$scope.browsers = ['IE', 'Chrome', 'Firefox','Safari','Opera'];
$scope.selection = {};
angular.forEach($scope.stories, function(story) {
$scope.selection[story] = {
browsers: {},
};
});
}
提前致谢。
【问题讨论】:
标签: javascript html angularjs checkbox