I am having difficulty working with Meteor.call
callbacks. I have defined a function which retrieves values from the server side; however, it does not return them to the template, in order to loop over them with an {{#each}}
loop.
Here is the function:
search: function() {
Meteor.call('mySearchFunction', arg1, function(err, res) {
if (err) console.log(err);
else if(res) {
console.log(res);
return res;
}
});
}
The console.log(res)
shows me the data that I need, which is properly fetched with mySearchFunction
, yet I am unable to pass it to the template handler, despite it being an array which may be iterated over. So I tried the following:
search: function() {
var s = Meteor.call('mySearchFunction', arg1, function(err, res) {
if (err) console.log(err);
else if(res) {
console.log(res);
return res;
}
});
console.log(s);
return s;
}
And console.log(res)
continues to display the requisite data, yet console.log(s)
appears as undefined
. I think this is because the async nature of meteor returns s
before res
gets a chance to be evaluated server-side. Either way, its strange that I cannot return data from a helper that I have stored in the helper function.