繁体   English   中英

找不到流星调用方法

[英]Meteor call method not found

我正在尝试学习流星和咖啡脚本,但是在尝试学习流星方法调用时遇到了麻烦。 我写了以下代码:

客户端/视图/家/ home.html做为

  <template name="home">
     Welcome to my new meteor app
     <input type="button" id='createFile' value="createFile" />
  </template>

客户端/视图/家/ home.coffee

Template.home.events
'click #createFile': ->
    Meteor.call 'alwaystrue', (error, result) ->
        console.log error
        console.log result
        return

    console.log 'You pressed the button'  if typeof console isnt 'undefined'
    return

服务器/ metodi.coffee

Meteor.methods
 alwaystrue: -> 
  true

单击该按钮时,应使用Meteor.call从客户端调用服务器方法,但它表示未找到alwaystrue方法。

我究竟做错了什么? 为什么我的代码看不到方法?

我从以下样板开始: https : //github.com/Differential/meteor-boilerplate ,在最新的ubuntu(14.04)上使用最新的node.js / meteor。

经过仔细的检查,我没有发现代码有什么问题,这使我相信问题之外的东西是混乱的。 尝试类似的事情:

  • 确保所有文件都已保存。
  • 确保所有CoffeeScript文件实际上以.coffee
  • 在所有情况下,请检查方法名称的拼写是否正确。

如果所有其他方法均失败,则可以创建一个单独的项目,只需添加此代码即可对其进行验证。

样式说明-CoffeeScript具有隐式返回,因此,除非您真的想返回undefined返回值或要从函数中早返回,否则,不需要Template.home.events的显式return语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM