01-22-2013 10:01 AM
Eric, thank you. I will try your code and let you know if it works.
01-22-2013 10:46 AM
Sorry but I'm not a javascript expert and I'm not used to callback functions.
Could I just return entries there and consider showEm returns an array of directory entries ?
function showEm() {
showLocalFileSystem(function (entries) {
//Do whatever I was interested in doing when this funciton returns
//Modify, etc etc
return entries;
console.log(entries);
});
}
01-22-2013 10:58 AM
Nope showEm has already been executed, but while it was executing it put your callback on the stack to be popped off when the showLocalFileSystem calls the callback. This is a non-blocking way of executing your code since JS is single threaded. The browser will go off do other things then your code will be run later.
You are wrapping any of your code in a function, so that you only execute it when the directories have been properly read. the nice thing about a callback is that your code will be executed sequentially the minute that the callbcak is called from the showLocalFileSystem(callback) function.
I put comments where you want to put all your code, inside there you can call another sequential function or do anything you like. This is just a natural trick in JS to perform something in an asynchronous nature. You can't really return entries, since the showEm
function showEm() {
showLocalFileSystem(function (entries) {
//Do whatever I was interested in doing when this funciton returns
//Modify, etc etc
//showEm has already returned!
// Any code you want executed AFTER the showLocalFileSystem function should go here and below
// and will have access to the entries passed back through the anonymous callback this way
// it can then execute sequentially in a non-blocking way
console.log(entries);
});
}
01-23-2013 05:52 PM
Thanks erikjohnzon. It works for me. In fact all what I needed is the path:
blackberry.io.home + '/../app/native/'
There is no way for me to know the '../app/native' stuff otherwise than from you.
01-23-2013 06:34 PM