簡體   English   中英

如何告訴SimpleSchema更新當前的Meteor.user?

[英]How do I tell SimpleSchema to update the current Meteor.user?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM