A rookie question, but I am trying to understand how PapaParse (or anything else, for that matter) uses callbacks. When I use the following code:
Here is the revised full code:
<html>
<head>
<script src="papaparse.js"></script>
<script src="drawTable.js"></script>
</head>
<body>
<label>Load CSV file: </label><input type="file" id="fileInputCSV" /><br/>
Results:
<table id="outputTable" border=1 px>
<tbody id="objTable"></tbody>
</table>
<script type="text/javascript">
var csvData = [];
function GetCSV(doneCallback) {
var fileInput = document.getElementById('fileInputCSV');
Papa.parse(fileInput.files[0], {
header: true,
skipEmptyLines: true,
complete: function(results) {
console.log('Done.');
doneCallback(results);
}
});
}
}
GetCSV(function(csvData) {
console.table(csvData.data);
drawTable(csvData.data, "objTable");
});
</script>
</body>
</html>
I have to reload the page to get the console.table, and the object generated by PapaParse is unavailable outside the PapaParse function.
I know this has been asked in other forms, but always has been answered in jQuery. Is there a solution is plain JavaScript? I really need not just to be able to display the data, but actually to be able to use it.
PapaParse itself is noticeably quiet on such a basic use of their program....
Thanks!
Results: