我在Meteor中使用aldeed:simple-schema和Mongo集合。
我有一个由网格(x/y坐标)组成的集合。它有描述维度的字段和一个点数组,不能超出这些维度的界限。
我希望能够在坐标上定义一个约束,以防止它们超出网格的边界。下面是我想要做的事情:
MyGrid.attachSchema({
gridWidth: {
type: Number,
min: 1,
max: 100
},
gridHeight: {
type: Number,
min: 1,
max: 100
},
gridPoints: {
type: [Object],
minCount: 0
},
// HERE is what I want to do
'gridPoints.$.x': {
type: Number,
min: 0,
max: gridWidth - 1 // <--- THIS
},
'gridPoints.$.x': {
type: Number,
min: 0,
max: gridHeight - 1 // <--- THIS
}
});这样的事情有可能吗?我没有在simple-schema文档中找到它,所以可能没有,但对于支持这些类型的“引用”来说,这听起来并不太牵强……
发布于 2017-03-04 06:31:04
在SimpleSchema中有自定义的验证。
另外,你可能是在“锦上添花”。
https://github.com/aldeed/meteor-simple-schema#custom-validation
https://stackoverflow.com/questions/38334234
复制相似问题