jeudi 29 octobre 2015

How to Force a Reload from the Server?

I have a page that gets a default list of data from the server, and this page also has a search box that, when run, updates a query parameter and returns a new list of data to the same page. This works fine.

However, when I clear the search (either through an action or by hitting "back" in the browser), I want to get the default data fresh from the server, replacing whatever the search results were.

I think I have this most of the way there, because clearing out the query parameter does cause findAll() to ask the server for data again, and that also gives back the right data, but the store keeps all the previously retrieved records from the search, so now the user sees both the default set plus the records they got back from the search.

So, how do I force Ember Data to use what comes back from the API and overwrite whatever it had in the store?

Here's my route code. Despite having reload: true and refreshModel: true, it appears that neither are actually happening:

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

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire