Angularjs 获取checkbox所有选中的值

什么也不多说了,直接上代码

html代码



js代码

    $scope.data = {
      id: 1,
      id: 2,
      id: 3,
      id: 4
    }
    $scope.selected = [];
    var updateSelected = function(action, id) {
      if(action == 'add' & $scope.selected.indexOf(id) == -1) $scope.selected.push(id);
      if(action == 'remove' && $scope.selected.indexOf(id) != -1) vm.selected.splice($scope.selected.indexOf(id), 1);
    };

    vm.updateSelection = function($event, id) {
      var checkbox = $event.target;
      var action = (checkbox.checked ? 'add' : 'remove');
      updateSelected(action, id);
    };

    vm.isSelected = function(id) {
      return $scope.selected.indexOf(id) >= 0;
    };   /*checkbox选中*/

    $scope.selectAll = function() {
      $scope.selected = []
      if($scope.select_all) {
        angular.forEach(vm.data.list, function (i) {
          $scope.selected.push(i.id);
        })
      }
    };



你可能感兴趣的:(Angularjs)