【问题标题】:How do I tell SimpleSchema to update the current Meteor.user?如何告诉 SimpleSchema 更新当前的 Meteor.user?
【发布时间】:2014-10-09 14:14:50
【问题描述】:

我正在使用 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(),email 应该是已经存储在 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 文档中没有看到任何解释这一点的内容。

谢谢你:)

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    您的要求在 collection2 文档中进行了解释,这里: https://github.com/aldeed/meteor-collection2/#attach-a-schema-to-meteorusers

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 2015-08-02
      • 2016-06-20
      相关资源
      最近更新 更多