var data;
for (var i = 0, f; f = files[i]; i++) {
if (f.type == 'application/csv' || f.type == 'application/vnd.ms-excel' || f.type == 'text/csv') {
Papa.parse(f, {
header: true,
dynamicTyping: false,
complete: function(results) {
console.log("Completed parsing results", results);
data = results.data.slice(0); //I tried other simple values here, such as "test"
console.log("Data after assigned value.", data); //Here the data is correctly assigned to the variable
}
});
console.log("Value of data outside function.", data); //Undefined??
}
}
은 마지막을 console.log 라인이 어떤 결과를하지 않는 이유입니다 비동기이다 : 그것은 전에 구문 분석이 완료 실행합니다. 결과 처리는
complete
콜백 내부 또는 이후에 이루어져야합니다.
감사합니다. 내가 따라 왔던 예제는 그렇게하지 않았지만 어쨌든 결과와 아무런 관련이 없다고 생각합니다. – maddmenz