typeerror:无法在showheader(landing.js:9)>>的showtableonload(landing.js:17)>>的landing.js:42处读取null>>的属性'innerhtml'

4uqofj5v  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(177)

我正在编写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;
    });
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题