Rumah > Soal Jawab > teks badan
从后端获取数组如下:
$scope.arr = [
{
selected:true;
}
{
selected:true;
}
{
selected:true;
}
]
$scope.select = function(){
// 如何在不调用后端接口的情况下,修改ng-repeat中ng-checked的状态实现全选和反选?
}
<ul>
<li ng-repeat="i in arr">
<input type="checkbox" ng-checked="i.selected">
</li>
</ul>
<input type="checkbox" ng-click="select()">
给我你的怀抱2017-05-15 17:05:50
$scope.selectedAll = true;
$scope.arr = [
{
selected:true;
}
{
selected:true;
}
{
selected:true;
}
]
$scope.select = function(){
$scope.selectedAll = !$scope.selectedAll;
$scope.arr.forEach(function(item){
item.selected = $scope.selectedAll;
});
};
为情所困2017-05-15 17:05:50
$scope.arr = [
{ selected:true }
{ selected:true }
{ selected:true }
];
$scope.select = function(status){
$scope.arr.map(function(item){
item.selected = status === 'all'? true: !item.selected;
});
}
<ul>
<li ng-repeat="i in arr">
<input type="checkbox" ng-checked="i.selected">
</li>
</ul>
<button ng-click="select('all')">全选</button>
<button ng-click="select('inverse')">反选</button>
Pemilihan songsang di sini bermakna apabila tidak semua dipilih, yang dipilih menjadi tidak dipilih, dan yang tidak dipilih akan dipilih, tidak dikosongkan! ! !
Pembersihan adalah sedikit lebih rumit.
某草草2017-05-15 17:05:50
http://stackoverflow.com/questions/12648466/how-can-i-get-angular-js-checkboxes-with-select-unselect-all-functionality-and-i