0

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?

Community
  • 1
  • 1
user379468
  • 3,989
  • 10
  • 50
  • 68

1 Answers1

0

You can save it to a local null collection and use {{#each}}{{/each}}. For example:

Items = new Mongo.Collection(null);

Template.items.onCreated(function () {
  Meteor.call('myMethod', function (err, results) {
    if (!err) {
      results.forEach(function (item) {
        Items.insert(item);
      })
    }
  });
});

Template.items.helpers({
  items: function () {
    return Items.find();
  }
});

Then use an each.

{{#each items}}
  {{ value }}
{{/each}}
corvid
  • 10,733
  • 11
  • 61
  • 130
  • I suppose that solution would work, but I'm really just looking for a way to integrate meteor with the parse sdk without duplicating all my data, seem like maybe Meteor is not the right solution – user379468 Oct 13 '15 at 13:03
  • You wouldn't really be "duplicating" it because the null collection is not persisted on the server – corvid Oct 13 '15 at 13:06