Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to access my model's content in its respective controller but it initially returns a promise with undefined attributes, then when accessed a second or third time it returns the value.

Could it be there is a delay in retrieving data from the REST adapter?

Also trying to use '.then()' on the request in a controller does not work as I believe it for use 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 
    }
});

What is strange is that when I access the model's properties from the template view in a loop it returns them straight away.

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

Below is how I have set up the route. It's grabbing a list of equipment relevant to a specific 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);
  }
});
like image 995
oneiota Avatar asked Feb 25 '26 01:02

oneiota


1 Answers

Changing our API endpoint to support sideloading seems to have fixed the delay we were experiencing when making the this.get('model') request.

There is a small section in the ember guides that covers this: http://emberjs.com/guides/models/the-rest-adapter/

like image 82
oneiota Avatar answered Feb 26 '26 15:02

oneiota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!