如何通过两个参数和数组对ng-repeat进行排序?(How to sort ng-repeat by two parameters and array?)
在我的模板中,我使用ng-repeat="obj in list" 。
list是对象的位置:
0: { status : "active", category : "animal" } ...另外默认情况下我有$scope.filter = {}
当我处理click时:我填写这个$scope.filter :
$scope.filter["categories"].push("animal"); $scope.filter["categories"].push("human");如何在ng-repeat创建filter将与数组$scope.filter["categories"] ,并找到category对应$scope.filter["categories"]元素?
In my template I use ng-repeat="obj in list".
Where list is object:
0: { status : "active", category : "animal" } ...Also by default I have $scope.filter = {}
When I handle click: I fill this $scope.filter:
$scope.filter["categories"].push("animal"); $scope.filter["categories"].push("human");How to make that filter in ng-repeat will work with array $scope.filter["categories"] and will find elements where category is corresponding $scope.filter["categories"]?
最满意答案
您可以拥有自定义过滤器。
app.filter('myFilter', function() { return function(arrList, arrKeywords) { var arrFilterList = []; angular.forEach(arrList,function(oneVal,key){ if(arrKeywords.indexOf(oneVal)){ arrFilterList.push(oneVal); } }) return arrFilterList; } });You can have custom filter.
app.filter('myFilter', function() { return function(arrList, arrKeywords) { var arrFilterList = []; angular.forEach(arrList,function(oneVal,key){ if(arrKeywords.indexOf(oneVal)){ arrFilterList.push(oneVal); } }) return arrFilterList; } });更多推荐
发布评论