この投稿内の2つの質問ですが、経験豊富なjsの人にとってはおそらく簡単です:-)
初め; readEntries
「ファイル名」を渡すときに、内部で「ファイル名」が定義されていないのはなぜですか?
2番; ディレクトリが空のときに、なぜそれが常に正しいのですか?
これが私のコードです:getPicturepath
「women.png」のような文字列で呼び出しています。
function getPicturePath(filename){
alert(filename); //is correct
var reader = DATADIR.createReader();
reader.readEntries(function(entries, filename){
alert(filename);//is undefined ???
var doWeHaveIt = function(entries,filename){
checkForFile(entries,filename)
};
if(doWeHaveIt){
alert('allready have: '+DATADIR.fullPath+filename);
} else {
alert('need to download file: '+filename);
}
},onError);
}
function checkForFile(entries,filename){
console.log("The dir has "+entries.length+" entries.");
if(entries.indexOf(filename)!=-1){
alert(filename+' allready exists');
return true;
} else {
alert(filename+" doesn't exists");
return false;
}
}