1

有谁知道为什么在我的 Windows 8 应用程序中使用“fileEntry.file”总是失败?

如果我使用以下代码,它将失败:

Windows.Storage.StorageFile.getFileFromApplicationUriAsync(new Windows.Foundation.Uri(cordova.file.applicationDirectory + 'www/assets/pages/en/navigation.html')).done(usethisfile, fail);

function usethisfile(fileEntry) {
    console.log("Im going to use the file... " + fileEntry.path);
    fileEntry.file(function (file) {
        var reader = new FileReader();  
        reader.onloadend = function() {
            console.log("Successful file read: " + this.result);
        };  
        reader.readAsText(fileEntry);   
    }, onErrorReadFile);
}

但如果我删除 'fileEntry.file' 部分它工作正常:

Windows.Storage.StorageFile.getFileFromApplicationUriAsync(new Windows.Foundation.Uri(cordova.file.applicationDirectory + 'www/assets/pages/en/navigation.html')).done(usethisfile, fail);

function usethisfile(fileEntry) {
    console.log("Im going to use the file... " + fileEntry.path);
    //fileEntry.file(function (file) {
        var reader = new FileReader();  
        reader.onloadend = function() {
            console.log("Successful file read: " + this.result);
        };  
        reader.readAsText(fileEntry);   
    //}, onErrorReadFile);
}

官方文档说使用'fileEntry.file':https ://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html我已经在Android上运行了该应用程序和 Apple 商店,所以我希望我可以继续使用 Windows 版本中已经使用“fileEntry.file”的所有当前功能。

我得到的错误是:0x800a01b6 - JavaScript 运行时错误:对象不支持属性或方法“文件”。

如果有帮助的话,我正在通过命令行和 Visual Studio 使用 Cordova 来运行它。

4

1 回答 1

0

不是 100% 确定,但是在定义 onloadend 方法时尝试添加 e 参数

于 2016-05-26T15:40:30.617 回答