本文介绍了Lodash:当我嵌套Object时如何使用过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑这个例子。我正在使用
Consider this example. I am using Lodash
'data': [
{
'category': {
'uri': '/categories/0b092e7c-4d2c-4eba-8c4e-80937c9e483d',
'parent': 'Food',
'name': 'Costco'
},
'amount': '15.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'India Bazaar'
},
'amount': '10.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'Sprouts'
},
'amount': '11.1',
'debit': true
},
当我这样做时
_.filter(summary.data, {'debit': true})
我收回所有对象。
我想要什么?
我想要所有 category.parent =='Food',我该怎么做?
I want all the objects where category.parent == 'Food'
, how can I do that?
我试过
_.filter(summary.data, {'category.parent': 'Food'})
并且得到了
[]
推荐答案
_.filter(summary.data, function(item){
return item.category.parent === 'Food';
});
这篇关于Lodash:当我嵌套Object时如何使用过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!