angular.js - angular怎么修改ng-repeat的ng-checked状态?
漂亮男人
漂亮男人 2017-05-15 17:03:50
0
3
1061

从后端获取数组如下:

$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()">



漂亮男人
漂亮男人

reply all(3)
给我你的怀抱
$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;
    });
};
为情所困
$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>

The inverse selection here means that when not all are selected, the selected becomes unselected, and the unselected becomes selected, not cleared! ! !
Empty is a bit more complicated.

某草草

http://stackoverflow.com/questions/12648466/how-can-i-get-angular-js-checkboxes-with-select-unselect-all-functionality-and-i

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template