我知道这件事已经受到质疑,但实际上,我没有找到任何有用或可以理解的东西。
我有这段代码:
var pdfListPath = [];
function listDir(path) {
window.resolveLocalFileSystemURL(path,
function(fileSystem) {
var reader = fileSystem.createReader();
reader.readEntries(
function(entries) {
console.log(entries);
for (var i = 0; i == entries.length; i++) {
pdfListPath.push(entries[i]);
};
},
function(err) {
console.log(err)
}
);
},
function(err) {
console.log(err);
}
);
};
var pdfList = listDir(cordova.file.applicationDirectory + "www/pdf/");
console.log(pdfList);
console.log(pdfListPath);
我所期待的是pdfListPath
充满了什么,但我在控制台中得到的是“未定义的”。
entries
是一个填充数组,所以这有什么问题?
提前谢谢。
答案 0 :(得分:3)
你的for循环是错误的,你需要改变
for (var i = 0; i == entries.length; i++) {
pdfListPath.push(entries[i]);
};
到
for (var i = 0; i < entries.length; i++) {
pdfListPath.push(entries[i]);
};
(不是100%肯定,也许它甚至<=
你最好检查i
和entries.length
)