我在mongoose中有这个数据库:
xSchemaDef = {
questions: [],
editions:[{
created: Date,
responses: [{
created: Date,
answers: []
}]
}]
如何使用Lodash获取一个版本的所有答案属性? 我试过了:
y=_.pluck(xSchemaDef.editions, 'responses');
并得到所有响应数组的数组,但后来我尝试了:
_.pluck(y, 'answers');
并且未定义。谢谢!
答案 0 :(得分:1)
第一个pluck
将提取数组数组。在提取answers
:
y = _.pluck(xSchemaDef.editions, 'responses');
_.pluck(_.flatten(y), 'answers');