【发布时间】:2018-08-29 05:34:45
【问题描述】:
我正在遵循我所读到的作为使用 Meteor.call 的标准方法,但在这种情况下它的行为很奇怪:
客户:
Template.sometemplate.events({
'submit .somebutton'(event){
...
Meteor.call('stuff.someMethod', param1, function (err, res){
console.log(err);
console.log(res);
};
}
})
服务器/api/stuff.js:
Meteor.methods({
'stuff.someMethod'(param1){
...
Meteor.call('otherstuff.someOtherMethod', param1, function(err, res){
if(err){ throw new Meteor.Error(400,'wrong things');}
if(res) { return 'ok';}
}
);
}
})
服务器/api/otherstuff.js:
Meteor.methods({
'otherstuff.someOtherMethod'(param1){
...
return OtherStuff.findOne(query);
}
})
在客户端,我单击并立即看到 err 和 res 的 console.log 未定义。而在应用程序的其他部分,当客户端调用服务器方法时,它并没有调用另一个方法,客户端在执行异步回调之前等待答案。
我在调用另一个服务器方法的服务器方法中使用 Meteor.call 的方式一定有问题。场景是,例如我想插入一个文档,同时我想检查一些值,以便将它链接到其他集合中的其他文档。
非常感谢, T.
【问题讨论】:
标签: meteor async-await