简体   繁体   English

具有多个变量的Angularjs ng-repeat过滤器属性?

[英]Angularjs ng-repeat filter property with more than one variable?

I'm trying to something like 我正在尝试类似的东西

<ion-item class="item-icon-right " ng-repeat="project in jsonObj.Projects | filter:projectArea:true:ProjectStatus" type="item-text-wrap" ui-sref="tabs.detail({project:project['Project name']})">
  <div class="row">
    <div class="col col-45">
      <h2>{{project["Project name"]}}</h2>
      <h4>{{project["PM"]}}</h4>
    </div>

    <div class="col col-45"></div>
    <div class="col col-10">
      <span class="badge badge-assertive icon-badge"><i class="ion-ios-arrow-right"></i></span>
    </div>
  </div>
</ion-item>

Controller: 控制器:

angular.module('App')
 .controller('ProjectsController', function ($scope, $rootScope, $stateParams, $state) {
        $scope.projectArea = $stateParams.area;
        $scope.ProjectStatus = $stateParams.Project_Status;      
  });

Data: 数据:

{PM: "Oommen", Area: "Foods", Project name: "PLuM", Reviewer: "Alex", A&D Start Date: "7-Dec-15"…}$$hashKey: "object:31"A&D End Date: "15-Jan-16"A&D Start Date: "7-Dec-15"Area: "Foods"Build End Date: "TBD"Build Start Date: "TBD"Implementation date: "TBD"PM: "Oommen"Project Status: "Green"Project name: "PLuM"Reviewer: "Alex"SIT End Date: "TBD"SIT Start Date: "TBD"ST End Date: "TBD"ST Start Date: "TBD"Status: "HLD Phase Kickoff. Review to be planned early"}

I'm trying filter ng-repeat with Area and Project Status values. 我正在尝试使用“ 区域”和“ 项目状态”值过滤ng-repeat。 However it filters only based on Area . 但是它仅根据区域进行过滤。 Could you someone help to identify the problem? 你能帮助找出问题吗?

你可以链过滤器

 project in jsonObj.Projects | filter:projectArea:true | filter:ProjectStatus

Two options: 两种选择:

  1. Use multiple filters where one filter uses the result of the previous filter (chaining) 使用多个过滤器,其中一个过滤器使用前一个过滤器的结果(链接)

    ng-repeat="project in projects | myFirstFilter | mySecondFilter" ng-repeat =“项目中的项目| myFirstFilter | mySecondFilter”

  2. Pass on the data or object you want to add to the equation to the filter. 将要添加到等式中的数据或对象传递给过滤器。

    ng-repeat="project in projects | myFirstFilter:myData" ng-repeat =“项目中的项目| myFirstFilter:myData”

I'd go with the first option because it creates a clear separation of what each filter does. 我会选择第一个选项,因为它可以清楚地分隔每个滤镜的功能。 Makes it easier to test as well. 使测试更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM