2013-02-19 62 views
3

我正在構建一個基本的應用程序,其功能相當重要PhoneGap,因爲我試圖確定它可以/不能做什麼。我已經到了我想要刪除已在應用程序上下載的文件的階段,但它不起作用。我使用的大部分代碼是從http://docs.phonegap.com/en/2.4.0/cordova_file_file.md.html#FileEntry;PhoneGap文件刪除不工作

function removefile(){ 
     fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail); 

    } 

    function gotRemoveFileEntry(fileEntry){ 
     console.log(fileEntry); 
     fileEntry.file(gotFile, fail); 
     entry.remove(success, fail); 
    } 

    function success(entry) { 
     console.log("Removal succeeded"); 
    } 

    function fail(error) { 
     console.log("Error removing file: " + error.code); 
    } 

我用HTML調用它;

<button onclick="removefile();">remove file</button> 

代碼有問題嗎?我看不到它。

順便說一句,我編碼的iOS和Xcode中使用JavaScript,HTML和PhoneGap/Cordova。

我是相當新的iPhone的發展,因此任何幫助將是巨大的感謝了很多:)

回答

5

你的代碼是稍微偏離。請嘗試:

function removefile(){ 
    fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail); 
} 

function gotRemoveFileEntry(fileEntry){ 
    console.log(fileEntry); 
    fileEntry.remove(success, fail); 
} 

function success(entry) { 
    console.log("Removal succeeded"); 
} 

function fail(error) { 
    console.log("Error removing file: " + error.code); 
} 
+0

有,上面寫着'entry.remove(成功,失敗)的鏈接;',是的在我的代碼中的任何用途?我會把它放在我的按鈕中還是放在我的某個功能中?順便說一句,非常感謝你的回答:) xx – 2013-02-20 10:16:28

+0

當我把你的代碼放在... – 2013-02-20 10:17:14

+0

沒關係我沒有它:)非常感謝你這是一個驚人的幫助xx – 2013-02-20 11:50:41

0

舊條目。該API可能已經改變,但我能夠做到這一點是這樣的:

function success(entry) { 
    console.log("Removal succeeded"); 
} 

function fail(error) { 
    console.log("Error removing file: " + error.code); 
} 

resolveLocalFileSystemURL(cordova.file.dataDirectory + 'assets/icons/test.png', function(entry) { 
    console.log(entry); 
    entry.remove(success, fail); 
}) 
我把我的問題在API中