csv をアップロードできるアプリケーション用の小さなバックエンドを作成しました。csv を調べて JSON に解析する必要があります。これには PapaParse を使用しており、1 つのファイルを実行できます。ただし、複数のファイルをアップロードして解析する必要があります。ファイルをアップロードできますが、すべてのファイルを選択する方法がわかりません。
これが私のコードです: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
});
ファイル0のみを選択するJSの最初の行と関係があると確信していますが、空の括弧と他のいくつかのことを試しましたが、まだ1つのオブジェクトしか出力しません。