samedi 21 novembre 2015

Empty model in Route

I have the following route:

import Ember from 'ember';

export default Ember.Route.extend({
  ajax: Ember.inject.service(),

  queryParams: {
    search: {
      refreshModel: true
    }
  },

  beforeModel: function() {
    var params = this.paramsFor('recipes');
    var that = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
      that.get('ajax').request({
          url: "/recipes",
          method: "GET",
          data: {
            namePart: params.search
          }
        },
        function(response) {
          that.store.unloadAll("recipe");

          response.forEach(function(item) {
            that.store.push(that.store.normalize("recipe", item));
          });

          resolve();
        });
    });

  },

  model: function() {
    this.store.peekAll('recipe');
  }
});

And controller:

import Ember from 'ember';

export default Ember.Controller.extend({
  queryParams: ['search'],
  search: null
});

The request is successful. And I even see appropriate data in the store. But route/controller model is null. What I'm doing wrong?




Aucun commentaire:

Enregistrer un commentaire