2016-09-22 51 views
0

我需要一个帮助。我需要使用Angular.js从表格行中获取所有选中的数据。我在下面解释我的代码。如何使用Angular.js中的复选框获取表格行数据

<tr ng-repeat="gl in galleryDatas"> 
<td><input type="checkbox" name=""> {{$index+1}}</td> 
<td><img ng-src="upload/{{gl.image}}" border="0" name="image" style="width:100px; height:100px;" /></td> 
<td>{{gl.description}}</td> 
</tr> 

在这里,我需要的,而用户将点击复选框中的各行数据将检索到array.Please帮助我。该复选框

<td><input type="checkbox" ng-change="clickedRow(gl.checked)" name="" ng-model="gl.checked"></td> 

在控制器

+0

值得看的这个,小提琴好像你想要达到的目标:HTTP: (http://stackoverflow.com/a/14835160/4045532](http://stackoverflow.com/a/14835160/4045532) – Corporalis

+0

[如何绑定到AngularJS的复选框值列表](http:// stackoverflow .COM /问题/ 14514461 /如何做绑定到列表的-复选框值与 - angularjs) –

回答

0

使用NG-变化,

$scope.clickedRow = function(checked) { 
if (checked) { 
    //add to the list 
    } else { 
// remove from list 
    } 
} 
0

你可以通过这个过程

在你的控制器

实现:

$scope.galleryDatas = [ 
    { 
     name: 'something', 
     description: "name 1" 
    }, 
    { 
     name: 'another', 
     description: "name 2" 
    } 
    ]; 

    $scope.checkedValue = []; 

    $scope.saveInArray = function(index) { 
    if($scope.galleryDatas[index].checked) { 
     $scope.checkedValue.push($scope.galleryDatas[index]); 
    } else { 
     var newIndex = $scope.checkedValue.map(function(e) { return e.name; }).indexOf($scope.galleryDatas[index].name); 
     // for compare instead of "name" you should use that field is unique. ie: e.uniqueField 
     // and $scope.galleryDatas[index].uniqueField 
     if(newIndex !== -1) 
      $scope.checkedValue.splice(newIndex,1); 
    } 

    }; 

注:其中$scope.checkedValue阵列和未选中时检查行数据存储,然后从$scope.checkedValue阵列

和HTML删除:

<td><input type="checkbox" ng-model="gl.checked" ng-click="saveInArray($index)"> {{$index+1}}</td> 
相关问题