2014-03-28 6 views
0

바코드로 재고를 필터링하고 싶습니다. 이렇게 할 수 있습니까? 여기서 중요한 점은 내가 전달하는 바코드가 (서버의) 바코드 인벤토리와 동일하다면 $scope.inventories을 바코드와 일치하는 것으로 변경하는 것입니다. 그리고 $ scope.inventories는 일치하는 바코드 인벤토리로만 구성됩니다.필터 객체 데이터 angularjs

몇 가지 미친 오류가 발생했습니다. 어떤 도움, 개체 데이터를 필터링하는 방법? NG 반복에서 목록에

$scope.filterByBarcode = function(list, barcode) { 
    return list.filter(function(item){ 
     return item.barcode === barcode; 
    }); 
}; 

필터 : 템플릿

<ul ng-repeat="inventory in inventories"> 
    <li><a href="" ng-click="filter(inventory.barcode)">{{inventory.barcode}}</a></li> 
</ul> 

답변

0

필터링 항목

$scope.filter = function(barcode) { 
     var filtered = []; 
     for(var i = 0; i < $scope.inventories.length; i++){ 
      if($scope.inventories[i].barcode == barcode){ 
       filtered.push($scope.inventories[i]); 
      } 
     } 
     $scope.filtered_inventories = filtered; 
    }; 
+0

여기에서 나를 도울 수 있습니까? http://stackoverflow.com/questions/22712486/filter-objects-matching-details – Erick

0

필터를 정의에 대해 서로 다른 변수 이름을 작성

$scope.inventories = new Inventory().query().$object; 

$scope.filter = function(barcode) { 
     for(var i = 0; i < $scope.inventories.length; i++){ 
      if($scope.inventories[i].barcode == barcode){ 
       $scope.inventories = $scope.inventories[i]; 
      } 
     } 
    }; 

<ul ng-repeat="inventory in filterByBarcode(inventories, barcode)"> 
    <li><a href="" ng-click="inventory">{{inventory.barcode}}</a></li> <!-- Not sure if this is what you want to display --> 
</ul>