lundi 3 août 2015

Display RSVP data from multiple AJAX calls in Template Ember

I have been trying to render data from a RSVP call to my template but for some reason I cant get it to work, Ember Console shows my data in the model section but nothing is shown to the user....

My idea is to get data from a few APIs and render it in the template "The Ember Way" not sure what I'm missing.

This is how my my code looks so far:

My Model:

model: function(params) {
var articles = [];
var promises = {
  nyt: Ember.$.getJSON('THE URL GOES HERE'),
  reddit: Ember.$.getJSON('THE URL GOES HERE')
};

Ember.RSVP.hash(promises).then(function(results) {
  var nytFeed    = results.nyt.response.docs;
  var redditFeed = results.reddit.data.children;

  Ember.$.each(nytFeed, function(){
    articles.push({
      'url': this.web_url,
      'description': this.snippet,
      'news-type': this.section_name,
      'date': this.pub_date,
      'title': this.main
    });
  });

  Ember.$.each(redditFeed, function(){
    articles.push({
      'url': this.url,
      'description': this.url,
      'news-type': this.subreddit,
      'date': this.created_utc,
      'title': this.data.title
    });
  });
  // console.log(articles);
});
return articles;

}

And Template:

Feed

{{#each item in model}}

Is this working?

{{item.title}}

{{item.description}}

{{item.news-type}}

{{item.date}}

{{/each}}




Aucun commentaire:

Enregistrer un commentaire