vendredi 30 janvier 2015

Ember.js get 2 nested models in one route in asynchronous way

I have 2 calls to server, which proceed a long time (10-20 seconds). I need update information on page after first request (doesn't matters which) was finished. After second request finished - i need also update part of page.


How can be realised, because I've tried realise which Promises



App.IndexRoute = Ember.Route.extend({
model: function(){
return Ember.$.getJSON('url').then(firstMethod).then(secondMethod)
}
})


but it doesn't work, because secondMethod will be executed after firstMethod will be finished.


Also I tried use this code:



App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
first_data: Ember.$.getJSON('url1'),
second_data: Ember.$.getJSON('url2')
});
}
});


But I have the same trouble - data will be return after 2 calls will be finished.


How run asynchronously these 2 requests and do independent update part of data on page ?





Aucun commentaire:

Enregistrer un commentaire