Ember js waiting for this.get request / rest adapter lag controller

I try to access the contents of my model in the appropriate controller, but first it returns a promise with undefined attributes, and then when it refers to the second or third time it returns a value.

Could there be a delay in receiving data from the REST adapter?

Also the attempt to use '.then ()' in the request in the controller does not work, since I believe that it is used only in the route.

App.EquipmentsController = Ember.ArrayController.extend({
    getContentForMapping: function() {
        console.log(this.get('model').objectAt(1).get('contractor.name'));
        //returns undefined first time 
    }
});

It is strange that when I access the properties of a model from a template view in a loop, it immediately returns them.

{{#each equipment in model}}
   <p>{{equipment.contractor.name}}</p>
{{/each}}

The following describes how I set up the route. It captures a list of equipment related to a particular site:

App.EquipmentsRoute = Ember.Route.extend({
  model: function(){
      //Get the model for the selected site and grab its equipment list.  
      return this.modelFor('site').get('equipment'); 
  },
  //Set the model we just grabbed above as the model to use in the controller
  setupController: function(controller, model) { 
    controller.set('model', model);
  }
});
+3
source share
2 answers

API , , , this.get('model').

ember , : http://emberjs.com/guides/models/the-rest-adapter/

+2

, App.EquipmentsRoute setupController. content, hook.

controller.set('content', model);

App.EquipmentsRoute = Ember.Route.extend({
  [...] 
  setupController: function(controller, model) { 
    controller.set('content', model);
  }
});
0

All Articles