简体   繁体   English

如何在不使用 Javascript 中的 FileReaderSync 的情况下使 FileReader 异步?

[英]How to make FileReader Asyncronous without Using FileReaderSync in Javascript?

I am using FileReader for reading multiple files and folders through drag and drop in chrome using javascript.我正在使用 FileReader 通过使用 javascript 在 chrome 中拖放来读取多个文件和文件夹。 It is working properly, but problem is that i want to call function after all file and folder read completes.它工作正常,但问题是我想在所有文件和文件夹读取完成后调用函数。 I can't because it is asyncronous operation and FileReaderSync is not supported in chrome.我不能,因为它是异步操作,而且 chrome 不支持 FileReaderSync。 So is there any way to doing this?那么有没有办法做到这一点?

this is my code,这是我的代码,

entry.file(function (file) {

                        var reader = new FileReader();
                        reader.onloadend = function (e) {
                            data.push(this.result);

                        };

                        reader.readAsText(file);
                    });

As an example of what can be used here.作为此处可以使用的示例。 This is can't be used as "Copy&Paste" variant :这不能用作“复制和粘贴”变体:

var filesCount = "give here number of files";

var callbackFunction = function(){
    if(data.length == filesCount ){
        Console.log( "Assume this as the end of all files reading" );
    }
}
entry.file(function (file) {

    var reader = new FileReader();
    reader.onloadend = function (e) {
        data.push(this.result);
        callbackFunction();
    };

    reader.readAsText(file);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM