-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-data.js
54 lines (45 loc) · 1.21 KB
/
read-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// function getData(element){
// readData(element).then(function(rawData) {
// var dataJadi = [];
// var dataArray = [];
// dataArray = rawData.split("\n");
// // data[0] = ["x","y"];
// for(var i = 0; i<dataArray.length; i++)
// {
// dataJadi[i] = dataArray[i].split(",");
// for(var j = 0; j<dataJadi[i].length;j++)
// dataJadi[i][j] = Number(dataJadi[i][j]); // --> 'done!'
// }
// // $scope.data = dataJadi;
// console.log(dataJadi);
// alert("get data done")
// return dataJadi;
// });
// }
function readData(element) {
var promise = new Promise(function(resolve, reject) {
var w = 0;
var dataReturn;
var files = document.getElementById(element).files;
var file = files[0];
var reader = new FileReader();
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
dataReturn = evt.target.result;
}
};
var blob = file;
reader.readAsBinaryString(blob);
var cek = function(){
if(dataReturn == null)
{
setTimeout(cek,1000);
}else{
resolve(dataReturn);
}
}
cek();
});
return promise;
}