2
我已经创造了猫鼬架构这样的虚方法执行在猫鼬的虚方法:呼叫时发现()
UserSchema.virtual('fullName').get(function() {
return this.firstName + ' ' + this.lastName;
}).set(function(replacedName) {
this.set(this.firstName, replacedName);
});
而且在服务器执行find()方法:
User.find({}).exec(function(error, users) {
// I want to use virtual method for users array
users.set('fullName', 'Name will be replaced');
});
莫非我使用虚拟方法进行数组无循环吗? 我正在研究NodeJS和Mongoose。
我觉得不能因为猫鼬架构只适用于单一的对象,而不是数组对象。 – truonghm