filter deep nested属性返回空数组

时间:2016-02-28 20:15:01

标签: javascript lodash ecmascript-harmony

我有对象数组

var data = [{type:"A",parentPersonInfo:{id:1,fullname:'john smith'}},{type:"A",parentPersonInfo:   {id:1,fullname:'jim smith'}},{type:"B",parentPersonInfo:   {id:2,fullname:'jane smith'}}]

我想使用lodash来提取type = A和id = 1

的记录
const testId = 1;
_.filter(data,{'type':'A','data.parentPersonInfo.id':1});

但我得到[]

1 个答案:

答案 0 :(得分:0)

你能检查下面的代码是否有效吗?

_.filter(data, {type: 'A', parentPersonInfo: {id:1}});