Looking at HTML FileReader. I am struggling to extract the data from the fileReader. All examples I see use the data directly from the inbuilt FileReader function. I'm trying to pull the data out of the filereader and store it in the parent 'class'. However I have been unsuccessful.
function constructTS(name){
// Variables
this.name = name;
this.csv = "";
}
constructTS.prototype.load = function(files){
if (window.FileReader) {
// FileReader are supported.
var reader = new FileReader(); //Exe#1
reader.onload = function(e){ //Exe#2
var csv = reader.result //Exe#5
var allTextLines = csv.split(/\r\n|\n/); //Exe#6
var lines = []; //Exe#7
while (allTextLines.length) {
lines.push(allTextLines.shift().split(','));
}; //Exe#8
this.lines = lines; //Exe#9
};
var x = reader.readAsText(files); //Exe#3
} else {
alert('FileReader yeah.. browser issues.');
};
alert(reader.lines[0]); //Exe#4
};
The this in this.lines = lines; refers to the Filereader class and not the constructTS class. Thus the information is not stored. I also find it a little strange how it runs the entire function and then only reads in the file afterwards. I guess that is helpful for web functionality. Any idea how I can load the data into the class?