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;