我为我的应用程序编写了一个小后端,我可以在其中上传 csv。它需要通过 csv 并将它们解析为 JSON。我为此使用 PapaParse,我可以做一个文件。但是我需要上传多个文件并让它们解析。我可以上传文件,但是我不知道如何选择所有文件。
这是我的代码:HTML
<form class="import">
<div class="form-group">
<input type="file" class="form-control-file" id="fileToRead" multiple>
<small id="fileHelp" class="form-text text-muted">You can enter one day or multiple days. Please see another import for anything other than daily data</small><br>
</div>
<!-- this line... the id is in the importData.js file, overflow-y: auto is what makes this section scrollable-->
<p id="editor" style="border: 1px black dotted; width: 100%; height: 200px; overflow-y: auto;">Hopefully see something here</p>
</form>
这是js文件:
//Getting the document by the ID and when something changes it runs the function
document.getElementById("fileToRead").addEventListener("change",function(){
//creates a var for the first file.
var files = this.file[0]
Papa.parse(files, {
header:true,
dynamictyping:true,
complete:function(results){
console.log(results);
var data = results.split;
document.getElementById("editor").innerHTML = data;
}
});
//this prints the value of the evt.target.result (which is another pre-defined JS object that runs with
//FileReader woo hoo!) this has to have .innerHTML becuase I have a <p> tag, when it was a <textArea> it had
// to have .value
});
我很确定它与 JS 中的第一行仅选择文件 0 有关,但是我尝试了空括号和其他一些东西,但它仍然只输出一个对象。