[英]Meteor: Calling an asynchronous function inside a Meteor.method and returning the result
[英]Meteor 1.2.1 version Meteor.method({}) inside server code does not work
客户端单击sendlogmessage
调用该事件,但是服务器端程序内部的方法不会调用sendlogmessage
。
console.log
无效。 谁能帮我找到答案?
if (Meteor.isClient) {
Template.mytemplate.events({
"click": function () {
Meteor.call('sendLogMessage');
}
})
}
if (Meteor.isServer) {
Meteor.methods({
'sendLogMessage': function(){
console.log("Hello world");
}
});
}
您的代码正在工作。 您只需指定要单击的元素即可触发事件。 像这样:
HTML
<template name="mytemplate">
<p id="clicable">Click me!</p>
</template>
JAVASCRIPT
Template.mytemplate.events({
"click #clicable": function() {
Meteor.call('sendLogMessage');
}
})
要么
HTML
<template name="mytemplate">
<p class="clicable">Click me!</p>
</template>
JAVASCRIPT
Template.mytemplate.events({
"click .clicable": function() {
Meteor.call('sendLogMessage');
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.