I have read other answers here and couldn't exactly match my issue. Should be simple for someone with lots of experience in Promises. Code below, I need help fixing up the Recursive function because everything that happens in that ajax call is not available in first done. Code below will explain (Note the TypeScript syntax):
//Main
private Start(){
this.PopulateSomething().done(() => {
alert('done');
});
}
private PopulateSomething(): JQueryPromise<any> {
var dfd: JQueryDeferred<any> = jQuery.Deferred<any>();
//app.ExecuteAjax is just a wrapper for a ajax call.. note i'm using callbacks
app.ExecuteAjax("SomeParamater1", function (returnedObject) {
//Do something with returnedObject
$.each(returnedObject.something, function () {
app.RecursivelyDoSomething(this);
});
dfd.resolve();
});
return dfd.promise();
}
private RecursivelyDoSomething(Thing: any) {
//Do something with Thing
//Anything that happens within this Ajax call is not available when alert('done'); is executed
app.ExecuteAjax("SomeParamater1", function (returnedObject) {
$.each(returnedObject.something, function () {
app.RecursivelyDoSomething(this);
});
});
}