dimanche 21 avril 2019

Load additional data into Model via Controller in Ember.js

I'm trying to load some additional data into the Model via the controller. I'm using RSVP.js for making an async api call to fetch some data. The issue that I'm currently running into is, the api is taking some time to get the response and as such what is getting added to the Model via the controller is a Promise. I wanted to get the data out of the promise and then pass it on to the template, so that it can be rendered in the screen.

fetch : function(params) {
  var getProfile = '/api/fetch',
  metric = params.metric,
  qsParts, getProfileUrl;

  qsParts = {metric: metric};
  getProfileUrl = Ember.prefixAPIServer(buildUrl(getProfile, {}, qsParts));

  let promise =  Ember.RSVP.hash({
    result: Ember.$.getJSON(getProfileUrl)
   });

  this.get('model').resultData = promise.then(result => {
             return result;
  })
} 

I tried other ways of doing the last part of setting the resultData, but it's not working. Can anyone help me with it ? Basically I want the data that is being fetched from the API call to be set to the Model. Or is there any way of getting the data out of the Promise in the template , which is using Handlebars.js ?




Aucun commentaire:

Enregistrer un commentaire