mercredi 9 août 2017

What namespace changes happen when using multiple models in Ember 2.0?

I have a small Ember 2.0 app that takes hits a Rails app with an endpoint for a list of players from a game (in this case, Dota) and displays a sorted list of those players. I was able to do this successfully with one list. I'm having trouble passing the data correctly down to my templates, however, when trying to render two lists from two models.

I am able retrieve both end points from my Rails app for both models, but I'm getting a Cannot read property 'sortBy' of undefined when it comes to rendering the list for the second model (in this case, a list of StarCraft players).

It seems to me that there is there something wrong with my name-spacing or naming convention when Ember 2.0 is handling multiple models, since the format of the data in both models (starcraft and dota) are identical.

This is my how I'm setting up my models in my index.js

export default Ember.Route.extend({


  model() {
    return Ember.RSVP.hash({
      dotaLadder: this.get('store').query('dota_ladder', { filter: { foo: bar },
        include: "dota_players" }).then(function(dotaladders) {
          return dotaladders.get('firstObject');
        }),
      starcraftLadder: this.get('store').query('starcraft_ladder', { filter: { foo: bar },
        include: "starcraft_players"}).then(function(starcraftladders) {
          return starcraftladders.get('firstObject');
      })
    });
  }

}); 

This is how my index.hbs look, which correctly render the first player-list component, but not the second (both models are called successfully and are in the same format)


<hr/>


then lastly there is the list-component...
player-list.hbs

<strong>this is a list</strong>

  <pre> |  |  |  | </pre>


player-list.

import Ember from 'ember';

export default Ember.Component.extend({
  sortedPlayers: Ember.computed('players', function() {
    return this.get('players').sortBy('currentPlacement');
  })

What am I doing wrong in trying to render the second list?




Aucun commentaire:

Enregistrer un commentaire