简体   繁体   English

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

[英]Meteor 1.2.1 version Meteor.method({}) inside server code does not work

Client-side click sendlogmessage calls the event, but the method inside the server-side program does not call sendlogmessage . 客户端单击sendlogmessage调用该事件,但是服务器端程序内部的方法不会调用sendlogmessage

console.log didn't work. console.log无效。 Can anyone help me finding the answer? 谁能帮我找到答案?

if (Meteor.isClient) {
    Template.mytemplate.events({
        "click": function () {
            Meteor.call('sendLogMessage');
        }
    })
}    

if (Meteor.isServer) {
    Meteor.methods({
        'sendLogMessage': function(){
            console.log("Hello world");
        }
    });
}

You code is working. 您的代码正在工作。 You just have to specify the element you are clicking on that should trigger the event. 您只需指定要单击的元素即可触发事件。 Something like this: 像这样:

HTML
<template name="mytemplate">
    <p id="clicable">Click me!</p>
</template>

JAVASCRIPT
Template.mytemplate.events({
    "click #clicable": function() {
        Meteor.call('sendLogMessage');
    }
})

or 要么

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