客户端点击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");
}
});
}
答案 0 :(得分:0)
你的代码正在运作。您只需指定要单击的元素即可触发事件。像这样:
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');
}
})