Meteor:从Meteor.methods调用函数
首先我想注意到我是流星的初学者。我不知道为什么这个代码:Meteor:从Meteor.methods调用函数,methods,meteor,call,Methods,Meteor,Call,首先我想注意到我是流星的初学者。我不知道为什么这个代码: Meteor.methods = fun: -> "This is message." if Meteor.isClient Template.hello.greeting = -> "Welcome to FirstApp." Template.hello.events = "click input": -> console.log "You pressed the
Meteor.methods =
fun: ->
"This is message."
if Meteor.isClient
Template.hello.greeting = ->
"Welcome to FirstApp."
Template.hello.events =
"click input": ->
console.log "You pressed the button."
在浏览器控制台中键入此行时:
Meteor.call("fun", function(err, res) { if(err) alert(err); else alert(res); });
allerts:Error:Method找不到[404],而不是“This is message.”。
为什么乐趣没有定义?您是否将此文件放在
客户端
目录中Meteor.methods
必须在服务器上定义fun
,以便正确触发回调
Meteor.methods的客户端版本仅定义本地存根。因为不应将Meteor.methods分配给函数。如果你这样做,你将永远只有一个功能 请尝试以下方法:
if Meteor.isServer
Meteor.methods({
fun: ->
"This is message."
})
我不知道coffeescript可以在客户端上使用。但是您的定义是错误的,因为事件是一个具有多个函数的对象
这是正确的(前提是coffeescript在客户端工作):
享受流星的乐趣,阅读
Template.hello.events({
"click input": ->
console.log "You pressed the button."
})