Monday 15 September 2014

javascript - value of loop variable in FileReader onloadend -


I am trying to process a list of files that were created via html5 dropzone / fileinput. File [] is not actually a filelist, but there is an array containing file object.

It works only when the file [] contains only 1-2 files, but with each other, the output of the console is the same (last file in the file []) for example 4 Files me 4 times to save "filereader.onloaded: file: save-view.html index: 4" - http: //www.html- with the last file.

 for  (var i = 0; i  

I have tried to create a filereader array (so that the var filereader never overwrites) and saving indexread as an additional member variable of the filereader (so do not assume Will be lost after I ++), but none of this works.

fileer with each loop of loop and loop being released every time There is no waiting for the callback before, so whenever the onload callback is triggered, there is probably no phyliter object associated with specific load events in filereader .

To ensure that you use the correct FileReader object in the callback usage, this keyword, or you can get it from the object provided for the callback;

  filereader.onloadend = event (event) {console.log ("filereader .loaded: file:" + this.myfile.name + "index:" + event.target.myindex ); // Here we call some other functions which is most likely not the cause of any problem}  

No comments:

Post a Comment