mercredi 18 février 2015

Emberjs - need to refresh model on transtionTo

I have an Emberjs app that has a search action that needs to be available from all routes. To accomplish this, I've defined the 'search' action in the application route like this:



App.ApplicationRoute = Ember.Route.extend({
actions: {
search: function (query) {
this.transitionTo('search', { queryParams: { q: query } });
}
}
});


The 'q' querystring parameter is defined in the SearchController:



App.SearchController = Ember.ArrayController.extend({
queryParams: ['q'],
q: ''
});


The search route calls a service that queries my database with the query parameter like this:



App.SearchRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('activity', { query: params.q }),
}
});


I know that the model hook is not called on transtionTo, but when the user is already on the search page and wants to search again with a different query, I need to reload the search route with a new model.


Is using transitionTo in the application route the wrong approach in this case?


Any ideas are greatly appreciated!





Aucun commentaire:

Enregistrer un commentaire