0

我一直在尝试userProfile通过将附加信息附加到Meteor.users使用以下包来创建一个:

  • 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();
});

为什么会发生这种情况,我该如何解决?

4

1 回答 1

0

尝试使用,

{{> quickForm schema=userSchema doc=user id="user-profile-form" type="update"}}

Template.UserProfile.helpers({
 userSchema: function () {
   return Schema.User;
  }
});
于 2016-06-22T11:52:40.583 回答