Template.quote.helpers({
bid:function()
{
var bit;
Meteor.call(‘getbid’,code,function(err,res){
bit = res;
});
return bit;
}
})
I want to return the result of the callback function, but before the result back, the undefined bit will be returned. how to return the value after getting the callback result?
is this a one time call per template instance, or is it bound to change during the lifetime of the template?
if it’s just a single occurrence, I’d move the method call to the Template.quote.created event, and communicate the result to the helper using a reactive variable:
Template.quote.created = function() {
var instance = this;
instance.currentBid = new ReactiveVar;
var code = this.data.code; // assuming you get the code in the data context
Meteor.call('getbid', code, function(err, res) {
instance.currentBid.set(res);
});
}
Template.quote.helpers({
bid: function() {
return Template.instance().currentBid.get();
}
});
quite horrible, but that’s where Meteor falls short.