FileReader在Ionic 2中没有触发onloadend [英] FileReader not firing onloadend in Ionic 2

查看:1372
本文介绍了FileReader在Ionic 2中没有触发onloadend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cordova-file-plugin读取本地文件。目前,我能够读取本地目录的内容并选择单个文件。但是我在获取文件内容方面遇到了问题。

I'm trying to read a local file using the cordova-file-plugin. At the moment I'm able to read the content of local directories and select a single file. But I have problems to get the content of the file.

这是从列表中选择文件后单击按钮调用的函数:

Here's my function that's called by clicking a button after selecting a file from list:

import() {
    window.resolveLocalFileSystemURL(this.file.nativeURL, this.gotFile, this.fail);
}

这是两个函数 gotFile 失败

fail(e) {
    console.log(e);
}

gotFile(fileEntry) {
    var file = fileEntry.nativeURL;

    fileEntry.file(function(file) {
        var reader = new FileReader();

        reader.onloadend = function(e) {
             console.log('onloadend()'); 
        };

        reader.readAsText(file);

        console.log(reader);
    }); 
}

我可以在日志中看到 reader with我的文件在结果下的所有想要的内容,但我无法得到它并使用它。 readyState 是2,但是没有调用所有内部reader.onloadend。使用Ionic 1,这段代码没有任何问题。

I can see in the log the reader with all the wanted content of my file under result, but I'm not able to get it and use it. The readyState is 2, but all inside reader.onloadend isn't called. With Ionic 1 this code works without any problems.

如果有人能帮助我,我会很高兴的。提前致谢!

I would be very glad, if there's anyone how can help me. Thanks in advance!

推荐答案

离子2中的已知问题

正在加载在cordova.js修复它之前的zone.js.

Loading zone.js before cordova.js fixes it.

特定于ionic2维持此序列顺序。

Specific to ionic2 maintain this sequence order.

< script src =build / polyfills.js>< / script> < script src =cordova.js< / script>

,因为polyfills.js执行zone.js。

as the polyfills.js executes the zone.js.

这篇关于FileReader在Ionic 2中没有触发onloadend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆