我们点击复选框时如何获取一个或多个数据?

时间:2017-10-04 12:46:59

标签: javascript html angularjs checkbox

我有一个问题,当我点击一个或全部选择时,所有数据都会出现。但是,当我点击单一复选框时,我只需要那些特定的数据。

  

html文件

<div class="row">
            <div class="col-md-12">
                <h1>Student Information</h1>
                <table id="example" class="table">
                    <tr>
                        <th>Name</th>
                        <th>Mobile</th>
                        <th>Siblling</th>
                        <th>select all <input type="checkbox" ng-click="vm.selectAll()"/></th>
                    </tr>
                    <tr ng-repeat="data in vm.data">
                        <td>{{data.name}}</td>
                        <td>{{data.mobileNumber}}</td>
                        <td>{{data.isMigrated}}</td>
                        <td><input type="checkbox" ng-model="data.selected" class="duplicateRow" /></td>
                    </tr>
                    <tr>
                    <tr>

                    <button class="button pull-right"  ng-click="vm.process()">Process</button>
                    </tr>
                </table>
                    <table class="table">
                        <tr>
                            <td colspan="4">
                                <pagination ng-if="renderpagination" page-number='{{vm.pageNumber}}' page-count="{{vm.pageCount}}" total-records="{{vm.totalRecords}}" api-url="duplicate-student"></pagination>
                            </td>
                        </tr>
                    </table>
           </div>
        </div>
  

Java脚本文件

vm.selectAll =function(){
      angular.forEach(vm.data, function(data){
       data.selected=true;
      });
    }
    vm.selectedUsers = [];

    vm.process = function() {
      vm.selectedUsers.splice(0, vm.selectedUsers.length);
      for (var i in vm.data) {
           vm.selectedUsers.push(vm.data[i]);
      }
    }  

1 个答案:

答案 0 :(得分:1)