samedi 21 mars 2015

Accessing store in another route

I have this model:



App.Game = DS.Model.extend({
name: attr(),
uri: attr()
});


and this route:



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


This works fine, calls the backend server, and stores elements in the store (I've checked with Ember inspector). This is the json I return:


{"games":[{"id":"TicTacToe","name":"TicTacToe","uri":"http://localhost:10000/games/TicTacToe"}]}


Now I have this template for 'games' (snipped):



{{#each game in model}}
{{#link-to 'games.matchlist' game.id}}{{game.uri}}{{/link-to}}


This shows the URI for each game. Now in the games.matchlist route what I would like to do is to search in the store by the game_id received param and get the game URI. The reason is that the server doesn't follow RESTAdapter conventions, and I would like to make a custom AJAX query to that URI myself. This doesn't work:



App.GamesMatchlistRoute = Ember.Route.extend({model: function(params) {
var store = this.store;
var game = store.find('game', params.game_id)
console.log(game);
console.log("URI: " + game.uri);


at this point, game is an object but it's not an instance of my model. It doesn't have a uri attribute. What am I doing wrong? I'm feeling that I'm missing something obvious.





Aucun commentaire:

Enregistrer un commentaire