【问题标题】:Using Meteor Autoform 'meteormethod' attribute callbacks?使用 Meteor Autoform 'meteormethod' 属性回调?
【发布时间】:2016-06-21 21:48:46
【问题描述】:
Schemas = {};

Schemas.ContactForm = new SimpleSchema({
  name: {
    type: String,
    label: "Your name",
    max: 50
  },
  email: {
    type: String,
    regEx: SimpleSchema.RegEx.Email,
    label: "E-mail address"
  },
  message: {
    type: String,
    label: "Message",
    max: 1000
  }
});

HTML:

<template name="contactForm">
  {{#autoForm schema=Schemas.ContactForm id="contactForm" type="method" meteormethod="sendEmail"}}
  <!-- etc. -->
  {{/autoForm}}
</template>

流星法,请查看cmets:

Meteor.methods({

  sendEmail: function(contents){
    check(contents, Schemas.ContactForm);
    Mandrill.messages.send({
      // do something to send
    }, function(error, response){
      if (error){
        // how does error bubble back up to the client?
      } else {
        // how does success bubble back up to the client?
      }
    })
  },

})

所以使用 AutoForm meteormethod 属性,我如何从我的服务器调用 Mandrill 获得错误或响应以冒泡回客户端,以便我可以通知用户表单已成功提交并通过电子邮件发送?

不使用 AutoForm 上的 meteormethod 属性并在表单提交时手动连接 Meteor.call 会更好吗?

【问题讨论】:

    标签: meteor mandrill meteor-autoform


    【解决方案1】:
    Meteor.methods({
    
      sendEmail: function(contents){
              check(contents, Schemas.ContactForm);
              return Mandrill.messages.send({
              // do something to send
              }, function(error, response){
                 if (error){
                   return error
                 } else {
                   return response
                 } 
    
      })},})
    

    【讨论】:

      【解决方案2】:

      尝试使用Meteor.wrapAsync 调用它并返回它。

      return Meteor.wrapAsync(Mandrill.messages.send, Mandrill.messages)(contents);
      

      【讨论】:

        猜你喜欢
        • 2015-01-01
        • 2015-09-20
        • 2019-02-14
        • 2015-02-28
        • 1970-01-01
        • 2015-03-09
        • 2016-03-30
        • 2015-10-22
        • 2016-08-14
        相关资源
        最近更新 更多