我刚开始使用FirefoxOS编码,并试图获取目录中的文件列表。FirefoxOS:使用设备存储API返回数组
想法是找到每个文件的名称并将其添加到数组(它的工作原理),但我想返回填充的数组,这就是我解开的地方。看起来数组在函数中被填充(因为我可以从中抽取文件名),但是当我想将它返回给另一个函数时,它看起来是空的?
下面是函数题:
function getImageFromDevice(){
var imageHolder = new Array();
var pics = navigator.getDeviceStorage('pictures');
// Let's browse all the images available
var cursor = pics.enumerate();
var imageList = new Array();
var count = 0;
cursor.onsuccess = function() {
var file = this.result;
console.log("File found: " + file.name);
count = count +1;
// Once we found a file we check if there are other results
if (!this.done) {
imageHolder[count] = file.name;
// Then we move to the next result, which call the cursor
// success with the next file as result.
this.continue();
}
console.log("file in array: "+ imageHolder[count]);
// this shows the filename
}
cursor.onerror = function() {
console.warn("No file found: " + this.error);
}
return imageHolder;
}
感谢您的帮助!