我收到此错误,
Exception while invoking method 'users_register' TypeError: Cannot read property 'validate' of undefined
当我执行此代码时,
Schemas.User.validate(user);
这是我的示例架构
Schemas = {};
Schemas.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z]{3,15}$/,
optional:true
},
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object,
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
optional:true
},
"emails.$.verified": {
type: Boolean,
optional:true
},
roles: {
type: Object,
optional: true
},
"roles.company": {
type: Array,
optional: true
},
"roles.company.$": {
type: String,
optional: true
},
profile: {
type: Object,
optional:true
},
"profile.first_name": {
type: String,
regEx: /^[a-zA-Z]{2,25}$/,
optional: true
},
"profile.last_name": {
type: String,
regEx: /^[a-zA-Z]{2,25}$/,
optional: true
},
"profile.retired":{
type:Number,
optional:true
},
services: {
type: Object,
optional: true,
blackbox: true
},
"profile.emails": {
type: Array,
optional: true
},
"profile.emails.$": {
type: Object,
optional: true
},
"profile.emails.$.user": {
type: String,
optional:true
},
"profile.emails.$.host": {
type: String,
optional:true
},
"profile.emails.$.port": {
type: String,
optional:true
},
"profile.emails.$.password": {
type: String,
optional:true
},
"profile.emails.$.status": {
type: Boolean,
optional:true
}
});
如何解决此错误?错误的原因是什么?我确信用户对象已定义并具有正确的属性。
任何人都可以帮我解决这个问题吗? 我的代码丢失了吗?
这是我的Simpl-schema的package.json部分, "简化模式":" 0.0.3",
在/server/main.js中,我添加了此代码,
import '../imports/api/users';
在users.js文件中,我添加了此代码,
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer) {
Meteor.publish ...
Schemas = {};
Schemas.User ... (code above)
Meteor.methods...
}