简体   繁体   English

流星回调返回未定义

[英]Meteor callbacks returning undefined

So I've recently started using Meteor.js, and although I appreciate its power, I'm having some issues with the way some of it works. 因此,我最近开始使用Meteor.js,尽管我欣赏它的强大功能,但其中一些工作方式仍存在一些问题。 I have a very basic couple of functions that I'm trying to use to get the hang of returning data to the client. 我有一些非常基本的功能,我正在尝试使用这些功能来将数据返回给客户端。

In my server folder: 在我的服务器文件夹中:

Meteor.methods({
"thing": (number) => {
    return number;
}
});

And then when it is used: 然后在使用它时:

const five = Meteor.call("thing", 5);
console.log(five);

But all I get is undefined 但是我得到的是undefined

This is so basic, I assume I must have a fundamental misunderstanding about how this process is supposed to work. 这是如此基本,我想我必须对这个过程的工作原理有一个基本的误解。 I have tried reading up on similar questions, but they mostly reference asynchronous processes, whereas this shouldn't wait on anything. 我已经尝试阅读类似的问题,但是它们大多引用异步过程,而这不应等待任何事情。

any communication from client to server is asynchronous, including Meteor methods. 从客户端到服务器的任何通信都是异步的,包括Meteor方法。 you're using a synch return value, which isn't what you're expecting. 您正在使用同步返回值,这不是您期望的值。

make it more like this: 使它更像这样:

    Meteor.call('thing', function(error, result) {
        if (error) {
            alert(error);
            return;
        }

        console.log(result);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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