2016-09-22 2 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> 

여기에 사용자가 각 행 데이터가 배열로 검색 할 확인란을 클릭하는 동안 필요합니다. 제발 도와주세요. 체크 박스 컨트롤러에서

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

+0

가, 바이올린은 당신이 무엇을 달성하고자하는 것 같다 : [HTTP : //stackoverflow.com/a/14835160/4045532](http://stackoverflow.com/a/14835160/4045532) – Corporalis

+0

[AngularJS로 체크 박스 값 목록에 바인딩하는 방법] 가능한 복제본 (http : // stackoverflow .com/questions/14514461/how-to-bind-to-list-of-checkbox-values-with-anglesjs) –

답변

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); 
    } 

    }; 

NB : 확인 행 데이터 저장소 $scope.checkedValue 배열하고 선택하지 않은 다음 $scope.checkedValue 배열

및 HTML에서 제거 :

이 보는 가치
<td><input type="checkbox" ng-model="gl.checked" ng-click="saveInArray($index)"> {{$index+1}}</td> 
관련 문제