0
嘿在這篇文章中的2個問題,他們可能很簡單,你有經驗的js球員:-)檢查手機中的文件目錄
首先;爲什麼當我傳遞它時,「文件名」在readEntries
內部未定義?
秒;爲什麼總是這樣,當目錄是空的時候?
繼承人我的代碼:我打電話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;
}
}
好吧,我明白了,我是一個可怕的@ JS。你能告訴我如何從函數checkIfFile ....返回true/false嗎? – 2012-07-19 10:54:31
不,我不想爲你編碼。我寧願讓你學習一些關於JS的東西。像函數聲明或函數實例化一樣。此外,這真是基礎。閱讀我在聊天室向你展示的教程將告訴你如何在不到一個小時的時間裏學習。 – 2012-07-19 10:57:04
好的,非常感謝 – 2012-07-19 10:58:16