ng-table:每行复选框选择

时间:2016-04-11 04:23:57

标签: angularjs ngtable

我有一个ng-table,我试图在每一行中使用复选框来实现选择。

 <table id="List" class=" table table-bordered table-striped"
  ng-table="tableParams" show-filter="true" template-pagination="custom/pager"> 

 <tbody>
      <tr ng-repeat="item in $data" >
          <td style="width: 35px">
    <input type="checkbox" name="selectedIds[]"  value="{{item.id}}" ng-checked="isRowSelected(item.id)" ng-click="toggleSelection(item.id)" />
        </td>
 <td data-title="'Name'" sortable="'Name'"  filter="{ 'Name': 'text' }" >
        {{ item.Name}} </a>   

    </td>
     <td data-title="'Email'" sortable="'Email'" >
        {{ item.Email}}
  </td>
  <td data-title="'Phone Number'" sortable="'PhoneNumber'"> 
      {{ item.PhoneNumber}}
            </td>
    </tr>

这是控制器:

angular.module("umbraco").controller("ListController",
 function ($scope, $http, $routeParams) {
$scope.selectedIds = [];
    $scope.toggleSelection = function (val) {
             var idx = $scope.selectedIds.indexOf(val);
             if (idx > -1) {
                 $scope.selectedIds.splice(idx, 1);
             } else {
                 $scope.selectedIds.push(val);
             }
         };

         $scope.isRowSelected = function (id) {
             return $scope.selectedIds.indexOf(id) >= 0;
         };
         $scope.isAnythingSelected = function () {
             return $scope.selectedIds.length > 0;
         };
});

我正在尝试选择单个行,但上面的代码选择任何行上的所有行单击。 对此有任何建议吗?

0 个答案:

没有答案