我想做的是这样的:
Schema
.virtual('getSomething')
.get(function(what) {
if (!what) {
return this.somethingElse
} else {
return this.something[what]
}
})
问题是我们无法在虚拟 getter 中传递参数,我怎样才能实现类似的东西而不必重复我的代码?
将其添加为实例方法 http://mongoosejs.com/docs/guide.html#methods而不是虚拟吸气剂。
schema.methods.getSomething = function(what) {
if (!what) {
return this.somethingElse
} else {
return this.something[what]
}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)