[英]Angular JS select all/De select all checkboxes how to retrieve selected information
[英]Select all if all checkboxes are selected, angular js
在我的頁面上,我有角ui手風琴,在每個面板內,我正在渲染包含項目和復選框的列表,也有復選框“全選”。 對於選擇方法和邏輯,我使用了此資源 。 在這種資源邏輯中,邏輯似乎有效,但是我在代碼中使用了該邏輯,但邏輯卻停止了。
我要實現的是選中所有復選框后,自動選中了“全選”復選框,如果未選中某些復選框,則也必須同時取消選中“全選”復選框。
我嘗試了這里 , 這里 , 這里提供的多個建議,但最終我得到了相同的結果。
我很高興有人可以幫助我解決我的問題。
$scope.categories = [
{
id: 1,
name: "category 1"
},
{
id: 2,
name: "category 2"
},
{
id: 3,
name: "category 3"
}
]
$scope.selectedAll = false;
$scope.selectAll = function(array) {
$scope.selectedAll = !$scope.selectedAll;
angular.forEach(array, function(item) {
item.Selected = $scope.selectedAll;
});
};
$scope.checkIfAllSelected = function(array) {
$scope.selectedAll = array.every(function(item) {
return item.Selected == true
})
};
html
<div>
<div class="row" ng-class="{'selected': selectedAll, 'default': !selectedAll}">
<div>Select all
<input type="checkbox"
ng-model="selectedAll" ng-click="selectAll(categories)" >
</div>
</div>
<div class="row" ng-repeat="item in categories | orderBy : 'id'" ng-class="{'selected': item.selected, 'default': !item.selected}">
<div > {{ item.name }}
<input type="checkbox"
ng-model="item.Selected" ng-click="checkIfAllSelected(categories)"
>
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.