[英]How do I tell SimpleSchema to update the current Meteor.user?
I'm using the accounts-ui and autoform packages. 我正在使用accounts-ui和autoform包。 When the user is logged in there is a form to complete a basic user profile. 当用户登录后,会有一个表单来填写基本的用户配置文件。
I'm getting this returned from SimpleSchema: 我从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}]
The _id should just be the Meteor.userId() and the email should already be available in the user object, createdAt doesn't appear in the form anywhere. _id应该只是Meteor.userId()并且该电子邮件应该已经在用户对象中可用,createdAt不会以任何形式出现在表单中。
How do I tell SimpleSchema that the _id should be the Meteor.userId(), the email should be the value already stored in the Meteor.user and the createdAt value should be the current time on the server? 如何告诉SimpleSchema _id应该是Meteor.userId(),电子邮件应该是已经存储在Meteor.user中的值,而createdAt值应该是服务器上的当前时间?
This is my schema: 这是我的架构:
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);
These are the relevant helpers: 这些是相关的帮助者:
Template.signupForm.helpers({
users: function () {
return Meteor.users;
},
userSchema: function () {
return Schema.User;
}
});
Template.signupForm.editingDoc = function () {
return Meteor.users.findOne({_id: Meteor.userId()});
};
My template: 我的模板:
<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>
I don't see anything in the SimpleSchema documentation that explains this. 我在SimpleSchema文档中看不到有任何解释此内容的信息。
Thank you :) 谢谢 :)
您所要求的内容在collection2文档中进行了解释,位于此处: https : //github.com/aldeed/meteor-collection2/#attach-a-schema-to-meteorusers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.