I have a function that takes a callback as a parameter, this function has a child function inside of it that I need to actually execute the passed callback that was passed to the parent when it's (the child function) done.
Example:
function Update(callback){
var db = Ti.Database.open('xxxxx'); //Open local database
var data = Ti.Network.createHTTPClient(); //Open a URL to obtain data to put into db.
data.onload = function(){
//loop through JSON file obtained from HTTPClient and place data into the DB.
callback(); //I need THIS to trigger the parents callback to tell the next function that Update() is done.
}
data.open("GET","URL");
data.send();
}
I'm pretty unexperienced when it comes to callbacks, so maybe I'm over thinking this one. Any help would be appreciated! Thanks all!
EDIT: Fixed - This code above works as expected. Somehow, because this Update function was being called while the DB was being created (another function creates the DB, then that callback function calls this Update function), it was still updating the DB, but wasn't calling the callback inside onload. I called the callback to trigger Update later, and it now works as expected. There were never any errors in the Appcelerator Console, so I'm not exactly sure how or why the DB was updated without the callback being called, but it was.