[英]How to iterate through an array containing objects in Meteor implementing SimpleSchema
[英]Meteor SimpleSchema Repeated Nested Objects
我想知道是否有一種簡單的方法可以做到這一點。 首先,這是我當前的模式:
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 },
});
在我有LOVE變量的地方,我希望它等於多個值,這樣我就不必一遍又一遍地編寫相同的模式。
我以為我可以使用正則表達式之類的東西,但我不知道。 有人可以幫忙嗎?
只需使用嵌套模式:
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},
});
然后在原始架構中重用它:
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...
});
希望這就是你所追求的。
應該吧
relations : { type : [boolean] }
所以那么你會
LOVE.relations
作為說8個條目的集合。 無需將其限制為我假設的這8個。
您可能使用了不同的術語,也許是事務或更好的匹配詞,但其背后的想法只是將其用於收集目的的使用方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.