2017-01-07 90 views
0

我在我的函數中給出了代碼。如何在angularjs中的控制器中使用過濾器

$scope.FilteredList = $filter('filter')(ProductService.Products, $scope.FilterExpr, false); 

其中$scope.FilterExpr與文本字段綁定。

上面的過濾器按照我的預期工作,當用戶在文本字段中鍵入內容時,$scope.FilteredList會填充已過濾的項目。

ProductService.Products是在對象中包含以下字段的對象數組。 namemrpspincart

我想創建另一個過濾器可過濾所有的項目,其中incart值> 0

我應該怎樣,而不是?????使用下面一行。

$scope.FilteredList = $filter('filter')(ProductService.Products, ?????, false); 

回答

1

您不需要再次使用$filter。請使用.filter而不是$scope.FilteredList集合來獲得所需的結果。

var result = $scope.FilteredList.filter(function(item){ 
    return item.incart > 0; 
}); 
+0

謝謝潘卡。它爲我工作。 :) –

相關問題