I have implemented the following code to parse a CSV via a <input type="file" />
selection:
export async function parse(file: File) {
let content = '';
const reader = new FileReader();
reader.onload = function(e: any) {
content = e.target.result;
};
await reader.readAsText(file);
const result = content.split(/
|
/);
return result;
}
If I run this code and put a breakpoint on the line where I declare result
, it retrieves the contents of the file successfully. If I do not put any breakpoint, the content is empty. As you can see, I added await
to the line where the reader reads the file as text, but it's still not working.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…