mercredi 9 mars 2016

Ember-data queryRecord does not update template

  • Ember: 2.3.0
  • Ember Data: 2.3.2

I'm working with the DS.JSONAPIAdapter

I can't update my template when fetching data with queryRecord although data is correctly loaded.

export default Ember.Route.extend({
  model: function(params) {
    return this.store.queryRecord('question', {
      id: params.id,
      //include: 'question.something,question.otherthing'
    });
  }
});

The template does update when fetching data with findRecord.

export default Ember.Route.extend({
  model: function(params) {
    return this.store.findRecord('question', params.id);
  }
});

If I do something like this:

export default Ember.Route.extend({
  model: function(params) {

    if (this.store.hasRecordForId('question', params.id)) {
      return this.store.peekRecord('question', params.id);
    }

    return this.store.queryRecord('question', {
      id: params.id
      // include: ''
    }).then(function(result){ return result; });
  }
});

The first time I go to the route, data is loaded but the template is not updated. Second time peekRecord() is used and template is updated.

How to update a template when queryRecord is used ? Thanks.




Aucun commentaire:

Enregistrer un commentaire