如何使用 javascript 在我的项目文件夹中的网页上显示 csv 文件的名称和数据(要从服务器获取的文件)
我的项目文件夹中有多个文件,它们是 csv 文件。我想从文件夹中获取所有文件名,并尝试在网页上显示其名称下的每个 csv 文件。这是我尝试使用的代码,但它显示了我给出完整路径的唯一文件。请帮助我获取所有文件并在网页中显示其数据。
<h1>Choose file and display its Name</h1>
<style>
td {
border: 2px solid blue;
}
</style>
<button onclick="showNames()">
Click Me To Get Student Details
</button>
<table></table>
<script>
newfiles=[]
newfiles=fetch("../static/csvfiles/")
console.log(newfiles)
// for file in fetch(
onload = fetch("../static/sysRestartTestData.csv").then(res => {
return res.text()
}).then(data => {
let result = data.split(/\r?\n|\r/).map(e => {
return e.split(",")
})
result.forEach(e => {
let m = e.map(e => {
return `<td>${e}</td>`;
}).join("")
let ce = document.createElement("tr");
ce.innerHTML = m;
if (ce.innerText != "") {
document.querySelector("table").appendChild(ce);
}
// console.log(m);
})
})
</script>
I have multiple files in a project folder which are csv files. I want to fetch all the files names from the folder and trying to display on webpage each csv file under its name. This is the code I am trying to use but its displaying the only file which I am giving the full path. Please help me to get all the files and display their data in webpage.
<h1>Choose file and display its Name</h1>
<style>
td {
border: 2px solid blue;
}
</style>
<button onclick="showNames()">
Click Me To Get Student Details
</button>
<table></table>
<script>
newfiles=[]
newfiles=fetch("../static/csvfiles/")
console.log(newfiles)
// for file in fetch(
onload = fetch("../static/sysRestartTestData.csv").then(res => {
return res.text()
}).then(data => {
let result = data.split(/\r?\n|\r/).map(e => {
return e.split(",")
})
result.forEach(e => {
let m = e.map(e => {
return `<td>${e}</td>`;
}).join("")
let ce = document.createElement("tr");
ce.innerHTML = m;
if (ce.innerText != "") {
document.querySelector("table").appendChild(ce);
}
// console.log(m);
})
})
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论