如何通过两个参数和数组对ng

编程入门 行业动态 更新时间:2024-10-20 01:24:41
如何通过两个参数和数组对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; } });

更多推荐

本文发布于:2023-08-06 21:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   参数   两个   ng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!