mardi 3 mai 2016

Ember js how to force reload of specific selected record?

I have the same problem as described here but do not understand how it applies to my situation, since I have no 'show' route.

I inherited this app, and the router.js looks like this:

App.Router.map(function() {
  this.route('index', {
    path: '/'
  });
  return this.resource('parent', {
    path: '/:parent_id'
  }, function() {
    this.resource('games', {
      path: '/games'
    });
    return this.resource('game', {
      path: '/game/:game_id'
    });
  });
});

The backend is Rails, and when the /games url is hit in Ember, it calls the games Index action in the Rails GamesController, as expected.

The games template renders each game:

<ul class="gamesList">

  
    <div class="gameItem-name u-before6of12 u-after1of12"></div>
    <div class="gameItem-description u-before6of12 u-after1of12"></div>
  


but when the game link is clicked, it loads the game from Ember store, and does not make a request to the API.

I need it to make a request to the API because: 1. The list of games includes only name and description, since the list can include many games, so we only want to load a subset of the data for each game. 2. An individual game, loaded by the Rails Show action, should use a different serializer to load all the additional content for a single game (including embedded child objects).

This is the Games route:

App.GamesRoute = Ember.Route.extend(Easypeasy.ResetScroll, {
  model: ->
    return this.store.find('game', {
      parent: @modelFor('parent').get('slug')
    })
})

and this is the Game route:

App.GameRoute = Ember.Route.extend(App.ResetScroll)

How do I trigger Ember to load the single game that the user clicks on?




Aucun commentaire:

Enregistrer un commentaire