Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
76 views
in Technique[技术] by (71.8m points)

javascript - HTML Table and Dates

I have a an HTML table I am attempting to populate from a Google Sheet. Two columns contain dates, and when I run the code to create the table it always produces an error in the forEach loop if there is a date in the cell. Is there a way for me to populate that information? I also update the sheet using a CRUD arrangement, and all works well save for the dates. TD [9] and [10] are the dates, and they are formatted (Year-Month-Date). The rest of the array is comprised of text or numbers. Thank you for your help.

function generateTable(dataArray){
 
 dataArray.forEach(function(r){
    var tbody = document.getElementById("table-body")
        var row = document.createElement("tr")
        var col1 = document.createElement("td")
        col1.textContent = r[0]
        var col2 = document.createElement("td")
        col2.textContent = r[1]
        var col3 = document.createElement("td")
        col3.textContent = r[2]
        var col4 = document.createElement("td")
        col4.textContent = r[3]
        var col5 = document.createElement("td")
        col5.textContent = r[4]
        var col6 = document.createElement("td")
        col6.textContent = r[5]
        var col7 = document.createElement("td")
        col7.textContent = r[6]
        var col8 = document.createElement("td")
        col8.textContent = r[7]
        var col9 = document.createElement("td")
        col9.textContent = r[8]
        var col10 = document.createElement("td")
        col10.textContent = r[9]
        var col11 = document.createElement("td")
        col11.textContent = r[10]
        var col12 = document.createElement("td")
        col12.textContent = r[11]
        var col13 = document.createElement("td")
        col13.textContent = r[12]
        var col14 = document.createElement("td")
        col14.textContent = r[13]
        var col15 = document.createElement("td")
        if(r[14] == ''){
        col15.textContent = ''
        }
        else{
          col15.textContent = '$' + r[14]
        }




       
        row.appendChild(col1).style = 'display:none'
        row.appendChild(col2)
        row.appendChild(col3)
        row.appendChild(col4)
        row.appendChild(col5).style = 'display:none'
        row.appendChild(col6)
        row.appendChild(col7)
        row.appendChild(col8).style = 'display:none'
        row.appendChild(col9).style = 'display:none'
        row.appendChild(col10)
        row.appendChild(col11).style = 'display:none'
        row.appendChild(col12).style = 'display:none'
        row.appendChild(col13).style = 'display:none'
        row.appendChild(col14).style = 'display:none'
        row.appendChild(col15)
        tbody.appendChild(row)
        
        })
 }
question from:https://stackoverflow.com/questions/65912307/html-table-and-dates

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...