我有一个简单的问题。我有一个过滤器,我传递一个数组并返回一个数组:
Filter返回由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}}
如何输出偶数值?
谢谢和最好的问候
答案 0 :(得分:1)
答案 1 :(得分:0)
myApp.filter('theFilter', function () {
return function(items){
return _.countBy(items, function(num) {
return num % 2 == 0 ? 'even': 'odd';
}).even;
};
});
答案 2 :(得分:0)
我想也许你需要写另一个过滤器:
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'}}