如何链AngularJS的控制器过滤器 [英] How to chain AngularJS filters in controller

查看:119
本文介绍了如何链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.

<一个href=\"http://plnkr.co/edit/Ej1O36aOrHoNdTMxH2vH?p=$p$pview\">http://plnkr.co/edit/Ej1O36aOrHoNdTMxH2vH?p=$p$pview

这篇关于如何链AngularJS的控制器过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆