0
我嘗試使用Phonegap getFile和createWriter函數在iOS應用程序(phonegap 2.1 + jquerymobile)上編寫大型文件。Phonegap 2.1 iOS:如何使用createWriter從數組循環寫入大文件
在包含數據JSON的數組「for」循環中,我有一個「getFile」函數,在我的fileSystem目錄中創建每個文件。 (這是工作) 在我的「getFile」函數中,我調用了一個調用phonegap createWriter函數並寫入數組數據文件的成功回調函數。 (問題在這裏)
我的問題是所有文件都包含最後一個數組數據。 我怎樣才能給每個文件的良好數據?
我的代碼:
fileSystem.root.getDirectory("directory",{create: true},
function(entry){
console.log('getDirectory success');
entry.getDirectory("subdirectory", {create: true},
function(entry){
console.log('subdirectory success');
for(var i=0, len= dataJson.length;i < len ; i++){
data = dataJson[i];
fullPath =data["data_id"]+".txt";
entry.getFile(fullPath, {create: true, exclusive: false},
function(fileEntry){
fileEntry.createWriter(
function(writer){
writer.onwriteend = function(evt) {
console.log("writer end");
};
writer.write(data["data_content"]);
writer.abort();
},
fail);
}
,fail);}
}
},fail);
}
,fail);
謝謝您的幫助。
能否請你建議我在我的功能有一定幫助,在一個循環中寫多文件http://stackoverflow.com/questions/16162652/facing-issue-writing-file-in-a -loop-使用JavaScript的 – user366584