0

この投稿内の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;
    }
}
4

1 に答える 1

1
reader.readEntries(function(entries, filename){

これは、パラメータ entriesとを定義する関数filenameです。

たとえば、この関数は次のようになります。

readEntries: function( callback ) {
    // do something, then
    callback( some, datas );
}

filenameこの関数で使用したいだけの場合は、それを使用してください。このような:

function getPicturePath(filename){
    alert(filename); //is correct
    var reader = DATADIR.createReader();
    reader.readEntries(function(entries){
        alert(filename);// is still correct

2番目の部分(常に真)はこれによるものです:

function hi() {}

if ( hi ) {
    // You're always getting there.
}

私が書いたことはまさにあなたがしたことです。私はあなたにそれを修正する方法を推測させます:-)

于 2012-07-19T10:45:34.103 に答える