筛选器深层嵌套属性返回空数组

filter deep nested property returns empty array

本文关键字:返回 数组 属性 嵌套 筛选      更新时间:2023-09-26

我有对象数组

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 提取类型 = A 和 id = 1 的记录

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

但我得到 []

你能检查一下使用以下代码是否有效吗?

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