jeudi 18 juin 2015

Model from Ember Data not rendering

I'm trying to figure out how to fetch data with Ember Data and render. After several problems I got to this point where I get no error on the console but the store is empty after the data is loaded.

window.App = Ember.Application.create();

App.IndexRoute = Ember.Route.extend({
  model: function(){
    return this.store.find('games');
  }
});

App.GamesModel = DS.Model.extend({
  name: DS.attr('string')
});

App.GamesAdapter = DS.RESTAdapter.extend({
  host: 'http://ift.tt/1GRCBae'
});

App.GamesSerializer = DS.RESTSerializer.extend({
  normalizePayload: function(payload){
    var result = { games: payload };
    return result;
  }
});

And this is the template:

<script type="text/x-handlebars" data-template-name="index">
  <ul>
    {{#each model}}
      <li>{{name}}</li>
    {{/each}}
  </ul>
</script>

Here is the link for the code on CodePen: http://ift.tt/1CeZUW3

I also tried different versions of Ember Data and Ember but with no luck.

Aucun commentaire:

Enregistrer un commentaire