Dynamic table row update in HTA (VBS)

After researching, I see that in order to dynamically update the table in HTA, I need to add an element tbody. I also see that then I need to use a function appendchildto add the necessary data / rows to the table.

I did this and am trying to loop through ArrLogsusing the code below

Dim i
i = 1
Set table = document.getElementById("maintable") 
Set tbody = document.createElement("tbody") 
table.appendChild(tbody) 
Set trow = document.createElement("tr") 
Set tcol = document.createElement("td") 

ArrLogs = ReadLogs(computerasset.value)

Do Until i = UBound(ArrLogs)
       tcol.innerHTML = ArrLogs(i) 
       trow.appendChild(tcol) 
       tbody.appendChild(trow)
       table.appendChild(tbody)  
       i = i+1
Loop

The problem I am facing is that I only see the last value of my array added to the table, almost the same as if I were absent from the command to save the append and overwrite the line as it goes through?

, , ( for i = 1 to UBound(ArrLogs) ..). -, .

+4
1

trow.appendChild(tcol) tcol ; , , tcol, , . B A

Set p = document.createElement("p") 
p.innerHTML = "A"
document.body.appendChild(p)
p.innerHTML = "B" 

, :

Dim i: i = 0

Set tbody = document.createElement("tbody") 

ArrLogs = ReadLogs(computerasset.value)

for i = lbound(ArrLogs) to ubound(ArrLogs)
    Set trow = document.createElement("tr") 
    Set tcol = document.createElement("td") 

    tcol.innerHTML = ArrLogs(i) 
    trow.appendChild(tcol)
    tbody.appendChild(trow)
Next

document.getElementById("maintable").appendChild(tbody)
+2

Source: https://habr.com/ru/post/1616175/


All Articles