문제

When I retrieve items from my list using REST API, I generate rows to an html table but when I try to append it to a table, I get the following errors:

Uncaught TypeError: Node.appendChild: Argument 1 is not an object.

function onQuerySucceeded(data) {

    if(data.d && data.d.results){
        var items = data.d.results
        var listItems = ''
        for (var x = 0; x < items.length; x++) {
            listItems += '<tr>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '</tr>'
        }
    }
    

    document.getElementById("service").appendChild(listItems)   //<---- Error
}

I know it's because listItems is not an object but I'm not sure how get it to where it needs to be.
Any ideas?

도움이 되었습니까?

해결책

This question is not related to SharePoint, however, you can use HTML DOM innerHTML Property if you want to show constructed HTML inside a DIV.

document.getElementById("service").innerHTML = listItems;

Details on innerHTML: https://www.w3schools.com/jsref/prop_html_innerhtml.asp

다른 팁

Or you could try to use jQuery:

$("#service").append(listItems)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top