Meteor simple-schema:根据另一个字段值设置最小/最大约束

时间:2016-07-12 16:19:42

标签: meteor simple-schema

我正在使用aldeed:简单模式与Meteor中的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
    }
});

这样的事情可能吗?我不是在简单模式文档中找到它,所以可能不是,但对于支持这些类型的“引用”来说听起来并不太牵强......

1 个答案:

答案 0 :(得分:0)

SimpleSchema中有自定义验证 此外,你可能会&#34;烫金百合&#34;这里。

https://github.com/aldeed/meteor-simple-schema#custom-validation