I have a helper function in my Meteor app as follows
Template.items.helpers({
data: function () {
return Template.instance().myAsyncValue.get();
}
});
Template.items.created = function (){
console.log('template created')
var self = this;
self.myAsyncValue = new ReactiveVar("Waiting for response from server...");
Meteor.call('get_itemes', function (err, asyncValue) {
if (err)
console.log(err);
else
self.myAsyncValue.set(asyncValue);
console.log('asyncValue'+asyncValue);
});
}
Template.items.rendered = function() {
console.log('template rendered')
};
I am basically trying to send that data over to template for display. Inside my get_items function, I am making an asynchronous call to Parse, to retrieve some objects. I've taken a look at this post but I'm still unclear as to what the preferred method to return async data to a template in meteor is.
Here is my get_items function
get_items: function() {
var Item = Parse.Object.extend("Item");
var query = new Parse.Query(Item);
query.find({
success: function(results) {
console.log("Successfully retrieved " + results.length + " scores.");
console.log(results);
return results
},
error: function(error) {
console.log("Error: " + error.code + " " + error.message);
return error;
}
});
}
even though I am logging success in the async function that is calling parse, it does not seem to be getting returned to the reactive variable, Am I implementing this wrong?