所以我在服务器文件夹中有一个像这样的方法:
dataHandler: function(id)
{
var data;
// here I call a server method
Meteor.call('getData', id, function(err, result)
{
data = result;
});
// now I want to use data in another method
Meteor.call('convertData', data, function(err, result)
{
data = result;
});
return data;
}
现在这不起作用,因为调用 Meteor.call('convertData' ... )
时的 data
将是未定义的。我该如何在无法使用 Session.set/get 的服务器端的 Meteor 中完成这项工作?
最佳答案
在服务器上,您可以选择同步调用方法。如果您不提供默认的回调函数。
If you do not pass a callback on the server, the method invocation will block until the method is complete. It will eventually return the return value of the method, or it will throw an exception if the method threw an exception. - http://docs.meteor.com/#meteor_call
你的代码应该像这样工作:
dataHandler: function(id) {
var data = Meteor.call('getData', id );
return Meteor.call('convertData', data );
}
关于javascript - 仅服务器上的 meteor 异步问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23666070/