0

I am developing a project that will have a table with a lot of content and I want to get the JSON content from an external file ("products.json") to have an better data organization.

Here is my Javascript file...

var domStructure = "";
    jsonObj = {
    "products": [
    {
        "ID": "01",
        "Name": "John",
        "Status": "Published"
    },
    {
        "ID": "02",
        "Name": "Paul",
        "Status": "Published"
    },
    {
        "ID": "03",
        "Name": "Nick",
        "Status": "Blacklist"
    }],
};

function getTableRow(id, name, status) {
    return '\
        <tr>\
            <td>' + id + '</td>\
            <td>' + name + '</td>\
            <td>' + status + '</td>\
        </tr>';
}

for(var key in jsonObj.products) {
    domStructure += getTableRow(jsonObj.products[key].ID, jsonObj.products[key].Name, jsonObj.products[key].Status);
}

document.getElementById('table').getElementsByTagName('tbody')[0].innerHTML = domStructure;
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ico Portela
  • 124
  • 1
  • 14

0 Answers0