Node.js 在Meteor中不使用Siml架构的方法上验证架构
我得到了这个错误Node.js 在Meteor中不使用Siml架构的方法上验证架构,node.js,reactjs,meteor,simple-schema,Node.js,Reactjs,Meteor,Simple Schema,我得到了这个错误 Exception while invoking method 'users_register' TypeError: Cannot read property 'validate' of undefined 当我执行这个代码时 Schemas.User.validate(user); import '../imports/api/users'; import SimpleSchema from 'simpl-schema'; if (Meteor.isServer) {
Exception while invoking method 'users_register' TypeError: Cannot read property 'validate' of undefined
当我执行这个代码时
Schemas.User.validate(user);
import '../imports/api/users';
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer) {
Meteor.publish ...
Schemas = {};
Schemas.User ... (code above)
Meteor.methods...
}
这是我的示例模式
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
}
});
如何修复此错误?错误的原因是什么?我确信用户对象已定义并具有正确的属性
有人能帮我解决这个问题吗?
我有丢失的代码吗
这是我的siml模式的package.json部分,
“简单模式”:“0.0.3”
在/server/main.js中,我添加了以下代码
Schemas.User.validate(user);
import '../imports/api/users';
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer) {
Meteor.publish ...
Schemas = {};
Schemas.User ... (code above)
Meteor.methods...
}
在users.js文件中,我添加了以下代码
Schemas.User.validate(user);
import '../imports/api/users';
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer) {
Meteor.publish ...
Schemas = {};
Schemas.User ... (code above)
Meteor.methods...
}
“简单模式”:“0.0.3”,这是打字错误吗?如果不是,0.0.3是非常早期的开发,因为最新的i0.3.1。尝试更新npm包,看看错误是否仍然存在或已经解决。我更新了它,但仍然不起作用,同样的问题。您可以发布更多文件代码a)您创建架构的位置。用户(是否导出它?)和b)您定义和调用用户的位置\u注册表I添加了一些代码。