2013-02-19 57 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中