代码之家  ›  专栏  ›  技术社区  ›  JMA

验证Meteor中不使用Simpl模式的方法的模式

  •  0
  • JMA  · 技术社区  · 8 年前

    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
    }
    });
    

    如何修复此错误?错误的原因是什么?我确信用户对象已定义并且具有正确的属性。

    谁能帮我解决这个问题? 我是否缺少代码?

    在/server/main中。js,我添加了这个代码,

    import '../imports/api/users';
    

    在用户中。js文件,我添加了这个代码,

    import SimpleSchema from 'simpl-schema';
    if (Meteor.isServer) {
        Meteor.publish ...
    Schemas = {};
    Schemas.User ... (code above)
    Meteor.methods...
    }
    
    0 回复  |  直到 8 年前