【发布时间】:2016-01-10 11:54:38
【问题描述】:
我一直在尝试通过使用以下软件包将附加信息附加到Meteor.users 来创建userProfile:
aldeed:simple-schema-
aldeed:Collection2 aldeed:AutoForm
更新表单生成并使用注册的电子邮件地址填充,但是我无法获得提交按钮来更新数据库中的任何内容。我的代码如下。
路径:collections/UserProfile.js
Schema = {};
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: true
},
lastName: {
type: String,
optional: true
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
}
});
Schema.User = new SimpleSchema({
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
autoValue: function() {
return new Date()
},
autoform: {
type: "hidden"
}
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true,
autoform: {
type: "hidden"
}
},
});
Meteor.users.allow({
update: function(userId, doc) {
return !!userId;
}
});
Meteor.users.attachSchema(Schema.User);
路径:client/UserProfile.js
Template.UserProfile.helpers({
user: function(){
return Meteor.user();
},
userSchema: function () {
return Schema.User;
}
});
路径:client/UserProfile.html
{{> quickForm collection="Meteor.users" doc=user id="user-profile-form" type="update"}}
路径:server/publish.js
Meteor.publish('allUsers', function () {
return Meteor.users.find();
});
为什么会发生这种情况,我该如何解决?
【问题讨论】:
-
我已编辑您的帖子以缩短它并使其更适合 SO。您确定需要整个架构来重现您的问题吗?看看什么是minimal reproducible example。
-
看看它是否在没有字段“emails.$”的情况下工作
-
感谢您帮助我格式化和缩短 SO @Kyll 的代码
-
我试图删除带有“emails.$”的字段,它只是让应用程序崩溃。
-
你有什么错误吗?还是提交按钮什么也没做?
标签: meteor meteor-collection2 simple-schema