[英]Meteor call method not found
I'm trying to learn Meteor and coffeescript, but I'm stuck while trying to learn meteor methods calls. 我正在尝试学习流星和咖啡脚本,但是在尝试学习流星方法调用时遇到了麻烦。 I wrote the following code: 我写了以下代码:
client/views/home/home.html 客户端/视图/家/ home.html做为
<template name="home">
Welcome to my new meteor app
<input type="button" id='createFile' value="createFile" />
</template>
client/views/home/home.coffee 客户端/视图/家/ 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
server/metodi.coffee 服务器/ metodi.coffee
Meteor.methods
alwaystrue: ->
true
The button when clicked should call a server method from the client, using Meteor.call , but it says that the alwaystrue method is not found. 单击该按钮时,应使用Meteor.call从客户端调用服务器方法,但它表示未找到alwaystrue方法。
What am I doing wrong? 我究竟做错了什么? why my code cant see the methods? 为什么我的代码看不到方法?
I'm starting from this boilerplate: https://github.com/Differential/meteor-boilerplate , whit the latest node.js/meteor, on the latest ubuntu (14.04). 我从以下样板开始: https : //github.com/Differential/meteor-boilerplate ,在最新的ubuntu(14.04)上使用最新的node.js / meteor。
After careful inspection, I don't see anything wrong with the code which leads me to believe something outside of the question is messed up. 经过仔细的检查,我没有发现代码有什么问题,这使我相信问题之外的东西是混乱的。 Try things like: 尝试类似的事情:
.coffee
. 确保所有CoffeeScript文件实际上以.coffee
。 If all else fails, you can create a separate project and just add this code to validate it. 如果所有其他方法均失败,则可以创建一个单独的项目,只需添加此代码即可对其进行验证。
Style note - CoffeeScript has implicit returns, so unless you really want to return undefined
or you want to return early from a function, you don't need the explicit return
statements in Template.home.events
. 样式说明-CoffeeScript具有隐式返回,因此,除非您真的想返回undefined
返回值或要从函数中早返回,否则,不需要Template.home.events
的显式return
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.