Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

Or you could try to use jQuery:

$("#service").append(listItems)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top