vendredi 7 août 2015

Clear data from Ember's Store before doing findAll

I have a search function working that will run a parameterized find(), but then I want to be able to go back to the state before the find, with only the records that were there before. In my app, this is the records the API returns with no query parameters.

My route's model hook

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

However, what currently happens is when the user goes back, all the records are still in the store, so when it does findAll(), it gets back both sets of records, when what I really want is for it to clear out the store, then use the records from the findAll(). The server API call is happening correctly in both places, it's just that the model hook is called with no params after it's been called once with params, then the store has extra records in it.

I tried doing this.store.unloadAll('project') before return this.store.findAll... but then I get a runtime error saying something it needed was deleted.




Aucun commentaire:

Enregistrer un commentaire