【问题标题】:filter deep nested property returns empty array过滤深层嵌套属性返回空数组
【发布时间】:2016-06-11 19:02:45
【问题描述】:

我有一个对象数组

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});

但我得到 []

【问题讨论】:

标签: javascript lodash ecmascript-harmony


【解决方案1】:

您能检查一下使用下面的代码是否有效吗?

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

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多