gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:39:40 25 4
gpt4 key购买 nike

我正在使用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

关于javascript - 我如何告诉 SimpleSchema 更新当前的 Meteor.user?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25333271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com