我有一个类似的代码:
Template.mytemplate.pippo = function() {
var returnValue;
asyncFunc(function (dataReturned) {
returnValue = dataReturned;
});
return returnValue;
}
我尝试在客户端加载未来
var Future = Npm.require('fibers/future');
但不要工作:(
我怎样才能等待 asyncFunc 返回回调完成返回模板值返回值
谢谢!
有一个
问题,你应该在哪里调用asyncFunc
,但是一旦你弄清楚了,你的代码应该看起来像这样:
asyncFunc(function (dataReturned) {
Session.set('returnValue', dataReturned);
});
...
Session.setDefault('returnValue', "loading.."); // or some other default that is safe
Template.mytemplate.pippo = function() {
return Session.get('returnValue');
}