【问题标题】:Does anyone know why using 'fileEntry.file' keeps failing in my Windows 8 app when trying to read a file?有谁知道为什么在尝试读取文件时在我的 Windows 8 应用程序中使用“fileEntry.file”总是失败?
【发布时间】:2016-05-26 15:34:45
【问题描述】:

有人知道为什么在我的 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 来运行它。

【问题讨论】:

标签: javascript cordova windows-8 cordova-plugin-file


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2018-02-02
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多