I have the following function:
downloadProductImage: function(remoteImage, localImageName){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(localImageName, {create: true, exclusive: false}, function(fileEntry) {
var localPath = fileEntry.fullPath;
var ft = new FileTransfer();
ft.download(remoteImage,
localPath, function(entry) {
//RETURN THIS imageURL = entry.fullPath;
}, fail);
}, fail);
}, fail);
}
The function downloadProductImage() is within global var app = {}, so accessed by app.downloadProductImage().
This function runs within a loop, and I wish to return the imageURL but can't seem to get it. I declare global var = imageURL outside the var app = {} but whenever I try to get imageURL in another function, the first loop returns undefined and the rest are correct.
I am not sure why the first loop through returns undefined.. the var imageURL is declared globally at the top of the page..
If I alert(imageURL) within the code above under //RETURN THIS imageURL = entry.fullPath;, it alerts correctly, just not when I try to access it outside the function
app.imageURL
) in the object and setting it toself.imageURL
wherevar self = this;
is placed before theft.download
line. It might help?