jeudi 11 mai 2017

Complex ember promise chain

I am having trouble with complex chained promises. Basically, I fetch data from my server. This data contains a URL. I fetch data from this URL. The data fetched from the URL has some information I need. Along with this, it has an array of other URLs. I am using ember. How do I fetch all these data nicely and return them as Ember.RSVP from the model hook of route? Here is my code:

model(params) {
let promiseArray = [];

let reportData = api.ajaxGet(api.buildV3EnterpriseUrl('reports'+ '/' + params.report_id))
                    .then(success => api.xmlRequest('GET',success.aggregationUrls.elements[0].url))
                    .then(reportData => JSON.parse('{' + reportData + '}'));

console.log(reportData);

return Ember.RSVP.hash({
  enterprise: this.store.findRecord('enterprise', session.get('enterpriseId')),
  reportData: reportData,
  individualData: promiseArray
});
}

The reportData result contains a bunch of deeply nested URLs. The reportData itself also has some additional information apart from the URL which I need. How do I fetch all of them in an elegant way?




Aucun commentaire:

Enregistrer un commentaire