【发布时间】:2021-08-06 07:16:48
【问题描述】:
我正在尝试了解如何使用 Meteor-Collection2 验证对象。我可以在下面的代码中更好地解释:
// This is the object structure to validate
// const obj = {
// name: 'Test',
// active: true,
// }
Test.schemaObj = {
someOtherName: {
type: String, // Not the same as obj variable
},
testType: {
type: Object,
// The goal is to define rules for validation for
// things that this will contain.
},
// Inside the object: {
// type: String,
// required: true,
//},
// Inside the object: {
// type: Boolean,
// required: true,
//},
};
我了解 required 在未定义时会自动设置为 true。
我的目的是基本上列出对象必须具有的所有键及其验证规则。我知道对象数组是如何工作的,只是不确定对象验证的语法是什么。
我浏览了文档和堆栈溢出,但我无法在网上找到明确显示语法的任何地方。
我确信我缺少一些基本的东西,但是我是新手,我希望有人可以帮助我。
【问题讨论】:
标签: javascript mongodb meteor meteor-collection2 simpl-schema