我正在尝试读取CSV文件数据,但出现错误。任何解决方案表示赞赏。添加libaray之后,它仍然无法工作
未捕获的TypeError:无法读取未定义的属性“ toArrays”
$(document).ready(function() {
// The event listener for the file upload
document.getElementById('File').addEventListener('change', upload, false);
// Method that checks that the browser supports the HTML5 File API
function browserSupportFileUpload() {
var isCompatible = false;
if (window.File && window.FileReader && window.FileList && window.Blob) {
isCompatible = true;
}
return isCompatible;
}
// Method that reads and processes the selected file
function upload(evt) {
if (!browserSupportFileUpload()) {
alert('The File APIs are not fully supported in this browser!');
} else {
var data = null;
var file = evt.target.files[0];
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event) {
var csvData = event.target.result;
data = $.csv.toArrays(csvData);
if (data && data.length > 0) {
// alert('Imported -' + data.length + '- rows successfully!');
$.each(data, function(index, value) {
$i = 0;
// console.log(value[$i]);
$('p').
})
} else {
alert('No data to import!');
}
};
reader.onerror = function() {
alert('Unable to read ' + file.fileName);
};
}
}
});