繁体   English   中英

服务器代码中的Meteor 1.2.1版本Meteor.method({})不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM