我的目标是打开一个CSV文件,然后使用PapaParse将其内容解析到<div>
。到目前为止,它似乎正在工作,但不是实际的值,它只是返回未定义。我不知道什么是错的,可能是一个奇怪的CSV文件(我使用另存为的Excel表格创建了这个文件),或者它可能只是草率编码。阅读CSV时,PapaParse返回undefined
JS
var data;
function handleFileSelect(evt) {
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function (results) {
data = results;
}
});
$(".graphcontainer").append("<div class='parse'>" + data + "</div>");
}
$(document).ready(function() {
$("#csv-file").change(handleFileSelect);
});
HTML
<div class="graphcontainer">Parser Output:</div>
<div class="buttoncontainer">
<input type="file" id="csv-file" name="files"/>
</div>
编辑:这里是我一直在(http://www.topdeckandwreck.com/excel%20graphs/)测试文件。不知道这是否真正相关,因为这样做的目标是让用户能够打开任何CSV文件,然后将图形制作出来:)
尝试使用不同的CSV文件后,它刚刚返回[对象对象] –
您可能想要将您正在使用的CSV文件添加到您的问题中。 – Tomalak