无法在MeteorJS中从客户端调用Meteor.call?

时间:2013-02-27 18:42:30

标签: meteor

使用meteor 0.5.7 - 遵循各方示例 - 制作客户端,服务器文件夹,并在其中放置相应的client.js和server.js文件。我有自动发布,不安全删除,并添加了电子邮件包。我无法启动Meteor.call,调试显示它被绕过,我松散地跟着这个 - http://goo.gl/MV26m - 我仍然不明白。

// server.js
Meteor.startup(function () {
  process.env.MAIL_URL = '...'; // using mailgun URL
});

Meteor.methods({
   call_me: function (options) {
     var options = options || {};
     Email.send({
      from: options.from,
      to: options.to,
      replyTo: options.from || undefined,
      subject: options.subj,
      text: options.msg,
     });
   },
});

// client.js
Template.form.events({
 'click .submit' : function (event, template) {
   var from = template.find("#from").value;
   var to = template.find("#to").value;
   var subj = template.find("#subj").value;
   var msg = template.find("#msg").value;
   var options = { from: from, to: to, subj: subj, msg:msg };

   Meteor.call('call_me', options, function(err, data) {
    if (err)
     console.log(err);
   });
 }
});

// client.html - the gist of it
<body>
  {{> page }}
</body>
<template name="page">
  {{> form }}
</template>
<template name="form">
  <form ....
</template>

最后,我实际上有Meteor.methods({...});坐在客户端/服务器文件夹之外的model.js文件中 - 它仍然没有触发电子邮件,或者调用Meteor.call方法。我有点试图绕过上述附加链接中存根的概念,将调用包裹在一个函数中并调用它,我仍然没有得到任何活动。谢谢你的建议。

1 个答案:

答案 0 :(得分:1)

试过你的要点。正在删除<form>代码并注释掉Process.env.MAIL_URL<form>标记阻止了按钮点击的事件触发器。

相关问题