var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ChildSchema = new Schema({
name: String
});
ChildSchema.methods.getName = function () {
return this.name;
}
var ParentSchema = new Schema({
children: {
type: [ChildSchema]
default: []
}
});
ParentSchema.methods.getChildName = function () {
// How to facilitate ability to access instance of ChildSchema to call child.getName
}
var Parent = mongoose.model('Parent', ParentSchema);
在上面的代码中,我希望在getName
中访问ChildSchema
的{{1}}方法。如何在猫鼬中完成?
提前多多感谢。
答案 0 :(得分:0)
请尝试使用"<tr><td>"+myDataFromDatabase+"</td>....</tr>"
作为参数,如下所示。
subdocument index