这是关于meteor的另一个异步主题,我对此感到抱歉!我读了很多关于wrapasync,promise,future,fibers等等的东西。我有点迷路了!
我的问题很简单,在我的代码中,我只需要返回返回当前主机名的服务器:
"getHost" : function(){
return this.connection.httpHeaders.host;
}我在onCreated帮助器中的程序乞求时调用此函数:
Template.printjoblistList.onCreated(function () {
Meteor.call("getHost", function(err, data){
if(err){
console.log("error " + err + " : " + data);
}else {
Session.set("printJobList_Host", data)
}
});
});问题是:我的Session.set是在我的Session.get之后执行的。此Session.get由以下代码执行:
在我的模板中:
<a href="{{getPdf}}">{{getPdf}}</a>在我的助手中:
Template.registerHelper("getPdf", function() {
var myReturn = Session.get('printJobList_Host'); + "/pdf/" + pdfFileName;
return myReturn;
});因此,我想了解一下如何使用wrapAsync来清楚地了解这一点!感谢您的帮助!
发布于 2016-03-30 04:07:36
Session.get可能发生在Session.set之前,但这应该没问题,因为当调用Session.set时,Session.get也会再次被调用(至少在常规帮助程序中是这样)。
如果这对您不起作用,请尝试在Tracker.autorun()中使用Session.get
https://stackoverflow.com/questions/36288081
复制相似问题