【发布时间】:2016-06-06 09:51:54
【问题描述】:
由于嵌套人口不可用,我需要手动传递我的自定义属性。在我的具体情况下,这意味着:一个客户有很多项目,一个项目有很多贡献者。
Customer.find().populate('projects').exec(function(err, customer) {
响应看起来像
[
{
"projects": [
{ "name": "First project" }
],
"customer": "John Doe"
},
{
"projects": [
{ "name": "Another project" },
{ "name": "And another one" }
],
"customer": "Susan Doe"
}
]
我正在遍历项目并想附加一个contributors 属性。我试过了
customer.forEach(function(customer, index) {
customer.projects.forEach(function(project, index) {
ProjectContributor.find({
project: project.id
}).exec(function(err, contributor) {
project.contributors = contributors;
});
但project.contributors 仍未定义。为什么?以及如何附加这些自定义属性?
【问题讨论】:
标签: javascript node.js sails.js