结构是
$scope.divisions = [
{ Description: 'test1', Id: 1 },
{ Description: 'test2', Id: 2 },
{ Description: 'test3', Id: 3 },
{ Description: 'test4', Id: 4 },
{ Description: 'test5', Id: 5 }
];
$scope.subd = [
{ Description: 'sub1', Id: 7 },
{ Description: 'sub2', Id: 8 },
{ Description: 'sub3', Id: 9 }
];如果选择了test1,应该在下面显示子d,可以选择subd。
我只想抓组织和子民的身份。
在柱塞http://plnkr.co/edit/hjb5HTITyJelqdjLN5h2?p=preview上检查它
发布于 2017-09-26 07:46:23
更新
如果仅在选择一个或多个子元素时才选择父输入,则可以考虑禁用父输入并根据所选子输入进行更新。
还将它们存储在一个新变量$scope.selected上,作为json。
<ul class="radio-check-group">
<li ng-repeat="d in divisions">
<input disabled type="checkbox" ng-model="d.selected" class="" id="{{'div' + d.Id}}" name="selectedDivisions[]" />
<label for="div{{$index}}">{{d.Description}}</label>
<ul>
<li ng-repeat="s in d.subd">
{{$parent.$index}}
<input type="checkbox" ng-change="updateParent(d)" ng-model="s.selected" class="" id="{{'div' + d.Id}}" name="selectedsubd[]" />
<label for="div{{$index}}">{{s.Description}}</label>
</li>
</ul>
</li>
</ul>以及控制器的功能:
function initializeDivisionSubd() {
angular.forEach($scope.divisions, d => {
d.subd = angular.copy($scope.subd);
})
};
$scope.selected = [];
initializeDivisionSubd();
$scope.updateParent = (parent) => {
parent.selected = !!parent.subd.find(s => s.selected);
$scope.selected = angular.toJson($scope.divisions.filter(d => d.selected).map(d => {
return {
Id: d.Id,
subd: d.subd.filter(sd => sd.selected).map(sd => {
return {
Id: sd.Id
}
})
}
}));这是更新小提琴
https://stackoverflow.com/questions/46420383
复制相似问题