如何链AngularJS的控制器过滤器

编程入门 行业动态 更新时间:2024-10-09 16:28:26
本文介绍了如何链AngularJS的控制器过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有鉴于一些过滤器

<tr ng-repeat="x in list | filter:search| offset:currentPage*pageSize| limitTo:pageSize ">

在我的项目取得好成绩,我不得不在控制器这种过滤不是针对

In my project to achieve good result, i have to make this filtering in controller not in view

我知道的基本语法 $过滤器('过滤器')('X','X'),但我不知道如何使过滤器链控制器,所以一切都将工作从模板我的例子。

i know the basic syntax $filter('filter')('x','x') but i don't know how to make chain of filters in controller, so everything will work as in my example from template.

我发现了一些解决方案,现在只是一个过滤器,但应该有许多工作;)

I found some solution, now just with one filter, but should work with many ;)

$scope.data = data; //my geojson from factory// $scope.geojson = {}; //i have to make empty object to extend it scope later with data, it is solution i found for leaflet // $scope.geojson.data = []; $scope.FilteredGeojson = function() { var result = $scope.data; if ($scope.data) { result = $filter('limitTo')(result,10); $scope.geojson.data = result; console.log('success'); } return result; };

和我使用此功能在NG-重复工作正常,但我有几个过滤器来检查一下。

and i use this function in ng-repeat works fine, but i have to check it with few filters.

推荐答案

您只需重新过滤什么你从你的第一个过滤器返回。等等等等。

You can just re-filter what you get returned from your first filter. So on and so forth.

var filtered; filtered = $filter('filter')($scope.list, {name: $scope.filterParams.nameSearch}); filtered = $filter('orderBy')(filtered, $scope.filterParams.order);

下面plunkr演示以上。

Below plunkr demonstrates the above.

plnkr.co/edit/Ej1O36aOrHoNdTMxH2vH?p=$p$pview

更多推荐

如何链AngularJS的控制器过滤器

本文发布于:2023-11-17 11:10:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609824.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   控制器   AngularJS

发布评论

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

>www.elefans.com

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