我正在尝试使用新的 HTML5 FileSystem API 来使用 javascript 创建/添加/删除文件。(用于自助收银台)
当前代码:
var entries;
function onInitFs(fs) {
fileSystem = fs;
debug('Opened file system: ' + fs.name);
loadFilelist();
// The functions below execute before loadFilelist() is ready!
setFileList(entries);
showFilenames(entries);
}
function loadFilelist() {
entries = [];
var dirReader = fileSystem.root.createReader();
readEntries();
function readEntries() {
dirReader.readEntries(function(results) {
if (results.length > 0) {
debug(results.length + " Files added to the filesystemFilelist");
entries = entries.concat(toArray(results));
entries.sort();
readEntries();
}else{
debug(entries.length + " Files in the filesystemFilelist");
//done
}
}, fileErrorHandler);
};
}
/* For putting debug text in the debug screen (in this case its the console) */
function debug(content) {
window.console.log(content);
}
问题在于函数 dirReader.readEntries(function (), callback) 等待回调。同时接下来的代码已经执行。我在File API中查找了它,似乎该函数仅适用于回调
我怎样才能防止函数调用
setFileList(entries);
showFilenames(entries);
在 loadFilelist 完成之前执行?
提前致谢