jeudi 12 octobre 2017

Ember JS - updated model property when fetching records after route has loaded

Say I have the following code in my route:

model() {
  return this.get('store').query('post', { author: 'John' });
},

actions: {
  fetchNewPosts: function() {
    this.get('store').query('post', { author: 'Sally' });
  }
}

Then the following in a component:

modelSubset: function() {
  return this.get('model').slice(0, 10);
}.property('model', 'model.@each'),

The computed property in the component updates fine when the route is entered, and the posts by author "John" are fetched in the model hook.

However, if I later fire the action fetchNewPosts the records are being fetched and added to Ember data, but the computed property in the component does not update.

Is there a way to fetch new records such that the model property will update?




Aucun commentaire:

Enregistrer un commentaire