I'm trying to return data from an Ajax call in a computed property. I understand because of the asynchronous nature, I can't do the following. However, I can't return a promise because I need to return the data in a particular format of an array with objects with a property and label.
options: Ember.computed('name', function() {
const url = '/testUrl';
let optionArray = [];
Ember.$.ajax({
url: url,
type: 'GET',
}).then((response) => {
let arr = JSON.parse(response);
for (let idx = 0; idx < arr.length; idx++) {
optionArray.addObject({
property: idx,
label: arr[idx]
});
}
return optionArray;
});
})
How do I return the data from the Ajax call in the format specified above?
Aucun commentaire:
Enregistrer un commentaire