子阵列上的角度ng-repeat滤镜 [英] Angular ng-repeat filter on subarray

查看:55
本文介绍了子阵列上的角度ng-repeat滤镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Angular,我尝试在给定以下架构的情况下对FactorName使用ng-repeat进行过滤.
使用过滤 < ... ng-model ="query.Factors.FactorName" ...>不起作用(不足为奇). 我还没有看到有关尝试以这种方式进行过滤的任何人的文献.

Using Angular, I'm trying to filter using ng-repeat on FactorName given the following schema.
Filtering using <... ng-model="query.Factors.FactorName" ...> doesn't work (not surprisingly). I haven't seen literature on anyone trying to filter in this way.

Angular是否支持基于子数组元素属性的过滤?

Does Angular support filtering based on a subarray element property ?

[
   {
      "Name":"1",
      "Factors":[
         {
            "FactorName":"FactorOne",
            "Type":"SomeType"
         },
         {
            "FactorName":"FactorTwo",
            "Type":"SomeType"
         }
      ]
   },
   {
      "Name":"2",
      "Factors":[
         {
            "FactorName":"FactorThree",
            "Type":"SomeType"
         },
         {
            "FactorName":"FactorFour",
            "Type":"SomeType"
         }
      ]
   }
]

推荐答案

还有另一个地方,您可以在带有自定义过滤器的双重绑定中沿ng-repeat边迭代数组.

There is also another place where you can iterate on a array, working along side ng-repeat, in the double bindings with a custom filter.

工作演示

HTML

<ul ng-repeat="x in factorData">
  <li>
    {{ x.Factors | factorFilter }}
  </li>
</ul>

JS

app.filter('factorFilter', function() {
    return function(items) {
        var results = [];
        if (items) {
            for (var i = 0; i < items.length; i++) {
                results = items[i]['FactorName'];
            }
            return results;
        } else {
          return 'Doh!';
        }
   }
})    

这篇关于子阵列上的角度ng-repeat滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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