0

I have an ajax call like so:

$.ajax(myAPI).done(parse(response));

Below is the success callback function to a previous API request:

parse(response) {
    let TreeObj= { 'Trees' : [] };

    response.ClassificationIds.forEach(classificationObj => {
        $.get('myAPI/' + classificationObj)
            .then((classification) => {
                TreeObj.Trees.push(classification);
            });
    });

    return TreeObj;
}

I'd like to return the TreeObj only after the forEach loop is finished looping. I'd like to do this by using promises, in particular $.Deferred by the jQuery library. How do I do this?

lorenzoid
  • 1,812
  • 10
  • 33
  • 51

0 Answers0