AngularJS: JSON 来自过滤器的数组

AngularJS: JSON array from Filter

我有一个简短的问题。我有一个过滤器,我在其中传递一个数组并取回一个数组:

过滤器 returns 由 underscore.js 库生成的 JSON 数组:

myApp.filter('theFilter', function () {
        return function(items){
            return _.countBy(items, function(num) {
              return num % 2 == 0 ? 'even': 'odd';
            });
        };
});

{{array | theFilter }} 仅输出一个 json 数组,如下所示:{{ "even":3, "odd":5 }}

如何输出 even 的值?

谢谢并致以最诚挚的问候

我试过了,效果很好

{{(items | theFilter).even}}

worked plnkr

myApp.filter('theFilter', function () {
    return function(items){
        return _.countBy(items, function(num) {
          return num % 2 == 0 ? 'even': 'odd';
        }).even;
    };
});

我想也许你需要再写一个过滤器:

myApp.filter('theFilter', function () {
        return function(items){
            return _.countBy(items, function(num) {
              return num % 2 == 0 ? 'even': 'odd';
            });
        };
});

myApp.filter('attr', function () {
        return function(obj, attrName){
            return obj ? obj[attrName] : undefined;
        };
});

{{array | theFilter | attr:'even'}}