问题描述
我想将我的 csvtojson 函数连接到 html(客户端),但是我遇到了一些错误。我应该有一个输入文件的监听器吗? 错误之一是需要未定义。但是我有一个带有 require 的 package.json
HTML 代码
<!DOCTYPE html>
<html lang="en">
<head>
<p>Convert CSV to JSON.</p>
<title>Swim API</title>
</head>
<script src='node.js' type='text/javascript'></script>
<body>
<p>Choose a csv to upload</p>
<input name="myFile" type="file" id="getBtn">
<button id="myBtn">Upload</button>
</body>
</html>
script.js
var x = document.getElementById("myBtn");
x.addEventListener("click",myFunction);
const csvtojsonV2=require('csvtojson')
function myFunction(){
csvtojsonV2({
noheader:true,checkType:true,headers:["Time","Yaw","Pitch","Roll","heading","Ax","Ay","Az","Gx","Gy","Gz","Mx","My","Mz"],})
.fromFile('getBtn')
.then((json) => {
const RESULT = json.reduce((acc,v,i) => {
for (const [key,value] of Object.entries(v)) {
if (!acc[key]) acc[key] = [];
acc[key].push(value);
}
return acc;
},{});
console.log(RESULT)
})
}
Package.json
{
"name": "requirejs","license": "MIT","volo": {
"url": "https://raw.github.com/requirejs/requirejs/{version}/require.js"
},"main": "require.js","scripts": {
"pretest": "jscs . && jshint require.js"
},"repository": {
"type": "git","url": "https://github.com/requirejs/requirejs.git"
},"devDependencies": {
"jscs": "^1.12.0","jshint": "^2.7.0"
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)