我正在使用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文档中没有看到任何解释这一点的内容。
谢谢:)
答案 0 :(得分:3)
您要求的内容在collection2文档中进行了解释,此处: https://github.com/aldeed/meteor-collection2/#attach-a-schema-to-meteorusers