我为我的应用程序编写了一个小型后端,可以上传csv。它需要经过csv并将其解析为JSON。我正在使用PapaParse,我可以做一个文件。不过,我需要上传多个文件并进行解析。我可以上传文件,但我无法弄清楚如何选择所有文件。使用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但是做我试过空括号和其他一些东西,它仍然只输出一个对象。