Javascript Meteor 1.2.1版本Meteor.method({})在服务器代码中不起作用
客户端单击Javascript Meteor 1.2.1版本Meteor.method({})在服务器代码中不起作用,javascript,meteor,npm,Javascript,Meteor,Npm,客户端单击sendlogmessage调用事件,但服务器端程序中的方法不调用sendlogmessage console.log不起作用。有人能帮我找到答案吗 if (Meteor.isClient) { Template.mytemplate.events({ "click": function () { Meteor.call('sendLogMessage'); } }) } if (Meteor.isSer
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
单击我
JAVASCRIPT
Template.mytemplate.events({
“click#clicable”:函数(){
Meteor.call('sendLogMessage');
}
})
或
HTML
点击我
JAVASCRIPT
Template.mytemplate.events({
“click.clicable”:函数(){
Meteor.call('sendLogMessage');
}
})
您没有为事件指定选择器。您确定客户端确实调用了服务器方法吗?
HTML
<template name="mytemplate">
<p class="clicable">Click me!</p>
</template>
JAVASCRIPT
Template.mytemplate.events({
"click .clicable": function() {
Meteor.call('sendLogMessage');
}
})