大佬教程收集整理的这篇文章主要介绍了node.js – Mongoose subschema array virtuals,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何以数组形式为Mongoose嵌套模式创建虚拟机?
以下是架构:
var Variation = new scheR_436_11845@a({ label: { type: String } }); var Product = new scheR_436_11845@a({ title: { type: String } variations: { type: [Variation] } });@H_301_16@我想如何虚拟变化.似乎如果子doc不是数组,那么我们可以简单地这样做:
Product.virtual('variations.name')...@H_301_16@但这只适用于非数组.
var Variation = new scheR_436_11845@a({ label: { type: String } }); // Virtual must be defined before the subscheR_436_11845@a is assigned to parent scheR_436_11845@a Variation.virtual("name").get(function() { // Parent is accessible var parent = this.parent(); return parent.title + ' ' + this.label; }); var Product = new scheR_436_11845@a({ title: { type: String } variations: { type: [Variation] } });@H_301_16@
以上是大佬教程为你收集整理的node.js – Mongoose subschema array virtuals全部内容,希望文章能够帮你解决node.js – Mongoose subschema array virtuals所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。