简体   繁体   English

流星SimpleSchema重复嵌套对象

[英]Meteor SimpleSchema Repeated Nested Objects

I'm wondering if there's a simple way of doing this. 我想知道是否有一种简单的方法可以做到这一点。 First this is my current schema: 首先,这是我当前的模式:

Test.schema = new SimpleSchema({
  owner: {
    type: String,
    label: 'Owner of the test',
  },
  name: {
    type: String,
    label: 'Name of the test',
  },
  createdAt: {
    type: Date,
    label: 'Date of test creation',
  },

  // MY QUESTION IS FOR THE OBJECT BELOW

  [LOVE]: {
    type: Object,
    label: `Configuration for ${LOVE}`,
  },
  [LOVE.one]: { type: Boolean },
  [LOVE.two]: { type: Boolean },
  [LOVE.three]: { type: Boolean },
  [LOVE.four]: { type: Boolean },
  [LOVE.five]: { type: Boolean },
  [LOVE.six]: { type: Boolean },
  [LOVE.seven]: { type: Boolean },
  [LOVE.eight]: { type: Boolean },
  [LOVE.nine]: { type: Boolean },
});

Where I have the LOVE variable, I would like it to be equal to multiple values so that I don't have to write the same schema over and over. 在我有LOVE变量的地方,我希望它等于多个值,这样我就不必一遍又一遍地编写相同的模式。

I thought I could use something like regex but I don't know. 我以为我可以使用正则表达式之类的东西,但我不知道。 Can someone help? 有人可以帮忙吗?

Just use a nested schema: 只需使用嵌套模式:

lovers = new SimpleSchema({
  one:   {type: boolean},
  two:   {type: boolean},
  three: {type: boolean},
  four:  {type: boolean},
  five:  {type: boolean},
  six:   {type: boolean},
  seven: {type: boolean},
  eight: {type: boolean},
  nine:  {type: boolean},
});

and then reuse it in your original schema: 然后在原始架构中重用它:

Test.schema = new SimpleSchema({
  owner: {
    type: String,
    label: 'Owner of the test',
  },
  name: {
    type: String,
    label: 'Name of the test',
  },
  createdAt: {
    type: Date,
    label: 'Date of test creation',
  },
  LOVE:    { type: lovers },
  PASSION: { type: lovers },
  DESIRE:  { type: lovers },
  etc...
});

Hopefully this is what you were after. 希望这就是你所追求的。

It should imho be 应该吧

  relations : { type : [boolean] }

So then you would have 所以那么你会

 LOVE.relations 

as a collection of say 8 entries. 作为说8个条目的集合。 No need to constraint it to these 8 i assume. 无需将其限制为我假设的这8个。

You might use a different term, maybe affairs or a better match, but the idea behind is just to use it the way a collection is meant to be used for the purpose. 您可能使用了不同的术语,也许是事务或更好的匹配词,但其背后的想法只是将其用于收集目的的使用方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在实现SimpleSchema的Meteor中遍历包含对象的数组 - How to iterate through an array containing objects in Meteor implementing SimpleSchema 在Meteor AutoForm SimpleSchema中验证日期值 - Validate date values in Meteor AutoForm SimpleSchema 流星服务器在SimpleSchema autoValue选项上崩溃 - Meteor server is crashing on SimpleSchema autoValue option TypeError:SimpleSchema不是Meteor 1.6项目中的构造函数 - TypeError: SimpleSchema is not a constructor in Meteor 1.6 project 流星js:使用validatedmethod simpleschema获取完整的验证消息 - Meteor js: get full validation message with validatedmethod simpleschema 如何告诉SimpleSchema更新当前的Meteor.user? - How do I tell SimpleSchema to update the current Meteor.user? 是否可以使用流星列出客户端中的SimpleSchema模式的allowedValues? - Is it possible to list the allowedValues of a SimpleSchema schema in the client using meteor? 如何在subschema Meteor js 1.8中声明simpleschema或 - How to declare simpleschema OR within subschema Meteor js 1.8 流星SimpleSchema +方法:单击得太快会引发错误 - Meteor SimpleSchema + Methods : clicking too fast throw an error 流星集合Simpleschema,自动值取决于其他字段值 - Meteor Collections Simpleschema, autovalue depending on other field values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM