我正在编写javascript文件以将json数据加载到表中,但我遇到了这个错误。请帮忙!
const showHeader= (headers)=>{
const tableArr=headers;
const tableMain=document.getElementById("tablebox");
let rowEle ='<tr class="header">';
tableArr.forEach(tableRow=>{
rowEle += `<th class='${String(tableRow).toLowerCase()}'>`+String(tableRow)+'</th>';
});
rowEle +='</tr>'
console.log(rowEle)
tableMain.innerHTML += rowEle;
}
const showTableOnLoad= (data, check=true)=>{
if(check)
showHeader(Object.keys(data[0]).map((headerString)=> headerString.toUpperCase()));
const tableArr=data;
const tableMain=document.getElementById("tablebox");
tableArr.forEach(tableRow=>{
let rowEle ='<tr>';
Object.entries(tableRow).forEach(entry =>{
const[key,value]=entry;
rowEle += '<td class="${key}">'+value+'</td>';
});
rowEle +='</tr>'
tableMain.innerHTML += rowEle;
});
}
暂无答案!
目前还没有任何答案,快来回答吧!