從後端取得數組如下:
$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.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>
這裡邊的反選說的是在不全選的情況下,選中變為未選中,未選中變選中,不是清空! ! !
清空的話要複雜一點。
某草草2017-05-15 17:05:50
http://stackoverflow.com/questions/12648466/how-can-i-get-angular-js-checkboxes-with-select-unselect-all-function性-and-i