简体   繁体   English

AngularJs过滤器未在嵌套对象中数组

[英]AngularJs Filter Not Array in Nested Object

I have a nested JSON data. 我有一个嵌套的JSON数据。 I am writing an object to a table by using ng-repeat from this JSON data. 我正在使用此JSON数据中的ng-repeat将对象写入表。 But I want to filter by a property this ng-repeat. 但是我想通过一个ng-repeat属性过滤。 How can I do this. 我怎样才能做到这一点。

Sample: 样品:

<tr ng-repeat="i in inspections.analizFirst">
    <td>{{$index+1}}</td><td>{{i.analiz}}</td><td>{{i.poi_adi}}</td><td>{{i.mesafe}}</td>
</tr>

It works without filter. 它无需过滤器即可工作。 But I need to filter like ng-repeat="i in inspections.analizFirst | filter:{analiz:'ulasim analizi'}" 但是我需要ng-repeat="i in inspections.analizFirst | filter:{analiz:'ulasim analizi'}"ng-repeat="i in inspections.analizFirst | filter:{analiz:'ulasim analizi'}"

Use controller: 使用控制器:

You can filter the data inside your controller and then refer to the filtered object in the html. 您可以过滤控制器内部的数据,然后引用html中的过滤对象。 It's usually more readable when you place all business logic in the controller 当您将所有业务逻辑放入控制器中时,通常更具可读性

Create your own filter: 创建自己的过滤器:

If you are planning to use this filter in multiple in the application, maybe its a good idea to create a new filter: 如果您打算在应用程序中多次使用此过滤器,则最好创建一个新过滤器:

appModule.filter('myFilter', function() {
  return function(orginalList, arg1, arg2) {
    var filteredObject = [];
    orginalList.forEach(function(e) {
      if(e.analiz === arg1)
           filteredObject.push(e) 
    })
    return filteredObject;
   };
 })

html html

<tr ng-repeat="i in inspections.analizFirst | myFilter:'ulasim analizi'">
  <td>{{$index+1}}</td><td>{{i.analiz}}</td><td>{{i.poi_adi}}</td><td>
 {{i.mesafe}}</td>
</tr>

Just like this: 像这样:

<tr ng-repeat="i in inspections.analizFirst | filter:'ulasim analizi'">
    <td>{{$index+1}}</td><td>{{i.analiz}}</td><td>{{i.poi_adi}}</td><td>{{i.mesafe}}</td>
</tr>

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

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