如何在 AngularJs 中获取 ng-model Checkbox 的集合?

How to get collection of ng-model Checkbox in AngularJs?

这是我的数据:

var fields = [
  {id: 1, name: 'Model'},
  {id: 2, name: 'Price'},
  {id: 3, name: 'Condition'},
  {id: 4, name: 'Ads Type'}
];

这是我的查看代码:

 <ion-checkbox ng-repeat="field in fields"
               ng-model="field.id"
               ng-checked="field.id">
               {{ field.name }}
 </ion-checkbox>
 <button class="button button-positive" ng-click="updateField()">
    Update SubCategory Field
 </button>

这是我的控制器代码

$scope.updateField = function(){
   // How can I get an Array of any Checked rows 
   // Expected result is: [2, 4]
}

我试过这个:

console.log($scope.field.id);

错误通过

Cannot read property 'id' of undefined

如有任何帮助,我们将不胜感激。

干杯

http://plnkr.co/edit/lOSaa9k7EEpgriz4AmaZ?p=preview

HTML

<!DOCTYPE html>
<html ng-app="app">

<head>
  <script   src="https://code.angularjs.org/1.3.9/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body>
  <h1>Hello Plunker!</h1>
  <div ng-controller="ctrl ">

   <input type="checkbox" ng-repeat="field in fields"
               ng-model="field.checked"
               ng-checked="field.checked">
               {{ field.name }} 
 </input>
 <button class="button button-positive" ng-click="updateField()">
    Update SubCategory Field
 </button>


          {{ selectedItems  | json }} 
  </div>
</body>

</html>

JS

var app = angular.module("app", [])

app.controller('ctrl', function($filter, $scope){

 $scope.fields = [
  {id: 1, name: 'Model'},
  {id: 2, name: 'Price'},
  {id: 3, name: 'Condition'},
  {id: 4, name: 'Ads Type'}
];

$scope.updateField = function(){

    var p = [];
    for (var i = 0; i < $scope.fields.length; i++) {
       var item = $scope.fields[i];
       if ( item.checked) {
        p.push(item )  
       }

    }

    $scope.selectedItems = p;
}

});