mercredi 21 octobre 2015

How to Navigate Back after a Parmeterized Query

I have a main route /projects that gets a few records from the API: return this.store.findAll('project', {reload: true}); Also on that page is a search box that will hit the same API, but with query parameters: return this.store.find('project', params); and obviously, this changes the URL in the address bar to something like /projects?q=acme and also shows only the records that were returned from the query. The route and template don't change, I'm just trying to swap out the model data.

My route code:

 model: function(params) {
    if (params.q) {
      return this.store.find('project', params);
    } else {
      return this.store.findAll('project', {reload: true});
    }
  },

My problem is that when you navigate back from this query, it shows all the records from first hitting the page plus the searched for records, when what I want it to do really is just ask for the default data from the API again. I don't want to use incorrect terminology, but I think what I want is to reload the store, but having {reload: true} doesn't seem to make any difference.

How can I reload fresh from the store when clearing out the query parameters?




Aucun commentaire:

Enregistrer un commentaire