我有不同类型的对象,我真的不想按键公开每个键,但这是让_.where()
工作的唯一方法。
有没有办法搜索多层次结构?
这是对象树:
{
type: 1
},
{
config: {
type: 2
}
},
{
name: "super"
}
以下是我想要达到的目标:
_.where(objectList,{config: {type: 2}})
返回
[{
config: {
type: 2
}
}]
答案 0 :(得分:0)
这可能不是复杂对象的最佳解决方案,但使用filter
适用于上述示例:
_.filter(objectList, function(v){
return _.isObject(v.config) && v.config.type == 2;
});