如何从angularjs中选中的复选框中获取值

时间:2017-01-23 11:00:33

标签: angularjs

onh 强文

当我使用json数据

单击右侧显示的基于复选框表ID的列名称时

1 个答案:

答案 0 :(得分:0)

JS

var app = angular.module('plunker', ['ui']);

app.controller('MyCtrl', function($scope) {
    $scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ];
    $scope.selected = {};
    $scope.ShowSelected = function() {
      $scope.records = $.grep($scope.records, function( record ) {
        return $scope.selected[ record.Id ];
      });
    };      
});

HTML

<div data-ng-controller="MyCtrl">
        <ul>
            <li data-ng-repeat="record in records">
                <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}}
            </li>
        </ul>
        <a href="javascript:;" data-ng-click="ShowSelected()">Show Selected</a>
    </div>