Phonegap 2.1 iOS : Lesen der Datei in app Ordner www

Ich versuche zu Lesen, eine Datei in meine iOS-app (phonegap 2.1 + jquerymobile) mit Phonegap getFile Funktion aber ich habe immer diesen Fehler :

Error in error callback: File3 = TypeError: 'undefined' is not an object

Meine Datei ist in www/data/datajson.txt und enthält einige json-Daten.

Mein code:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    //get www folder path
    var path = window.location.pathname;
    path = path.substr( path, path.length - 10 );
    var pathwww = path;
    console.log(pathwww); /* /var/mobile/Applications/{ID}/{APPNAME}.app/www/*/
    fileSystem.root.getFile("file//"+pathwww+"data/datajson.txt", null, gotFileEntry, fail);
    //result : Error in error callback: File3 = TypeError: 'undefined' is not an object
    pathwww.getFile("file///data/datajson.txt", null, gotFileEntry, fail);
    //result : Error in success callback: File2 = TypeError: 'undefined' is not a function
}

function gotFileEntry(fileEntry) {
    fileEntry.file(gotFile, fail);
}

function gotFile(file){
    readDataUrl(file);
    readAsText(file);
}

function readDataUrl(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as data URL");
        console.log(evt.target.result);
    };
    reader.readAsDataURL(file);
}

function readAsText(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as text");
        console.log(evt.target.result);
    };
    reader.readAsText(file);
}

function fail(evt) {
    console.log(evt.target.error.code);
}

Ich verstehe nicht, warum kann ich nicht navigieren in meinem www Ordner, und Lesen Sie meine datajson.txt Datei.

Danke für Sie Hilfe.

InformationsquelleAutor user1361189 | 2012-09-26
Schreibe einen Kommentar