繁体   English   中英

如何告诉SimpleSchema更新当前的Meteor.user?

[英]How do I tell SimpleSchema to update the current Meteor.user?

我正在使用accounts-ui和autoform包。 当用户登录后,会有一个表单来填写基本的用户配置文件。

我从SimpleSchema返回此信息:

SimpleSchema invalid keys for "signupForm" context: [Object { name="_id", type="required", value=null}, Object { name="email", type="required", value=null}, Object { name="createdAt", type="required", value=null}]

_id应该只是Meteor.userId()并且该电子邮件应该已经在用户对象中可用,createdAt不会以任何形式出现在表单中。

如何告诉SimpleSchema _id应该是Meteor.userId(),电子邮件应该是已经存储在Meteor.user中的值,而createdAt值应该是服务器上的当前时间?

这是我的架构:

    Schema.UserProfile = new SimpleSchema({
    firstName: {
        type: String,
        regEx: /^[a-zA-Z-]{2,25}$/
    },
    lastName: {
        type: String,
        regEx: /^[a-zA-Z]{2,25}$/
    },
    gender: {
        type: String,
        allowedValues: ['Male', 'Female']
    },
    bio: {
        type: String,
    },
    avatar: {
        type: String,
    },
    pinCode: {
        type: Number,
        min: 7,
        max: 7
    },
    phoneNumber: {
        type: Number,
        min: 9,
        max: 10
    }
});


    Schema.User = new SimpleSchema({
    _id: {
        type: String,
        regEx: SimpleSchema.RegEx.Id
    },
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
    },
    services: {
        type: Object,
        optional: true,
        blackbox: false
    }
});
SimpleSchema.debug = true;
Meteor.users.attachSchema(Schema.User);

这些是相关的帮助者:

Template.signupForm.helpers({
  users: function () {
   return Meteor.users;
  },
  userSchema: function () {
   return Schema.User;
  }
});



Template.signupForm.editingDoc = function () {
 return Meteor.users.findOne({_id: Meteor.userId()});
};

我的模板:

<template name="signupForm">
  <div class="panel-body">
    {{#autoForm collection=users schema=userSchema id="signupForm" type="insert"}}
    <fieldset>
      {{> afObjectField name='profile'}}
    </fieldset>

    <button type="submit" class="btn btn-primary">Insert</button>
   {{/autoForm}}
  </div>
</template>

我在SimpleSchema文档中看不到有任何解释此内容的信息。

谢谢 :)

您所要求的内容在collection2文档中进行了解释,位于此处: https : //github.com/aldeed/meteor-collection2/#attach-a-schema-to-meteorusers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM