{"airplane_models":[{"name":"A770","max_passenger":230},{"name":"A342","max_passenger":130},{"name":"A341","max_passenger":234},{"name":"B345","max_passenger":21}]}
In the text above i provide what was given in the xhttp response. Output was done via
window.alert(this.responseText)
then this gets passed to the function:
displayModels(JSON.parse(this.responseText))
then i have a function that is supposed to add insights of this array to the table:
/**
* Updates the DOM tree in order to display users.
*
* @param {Array.<{name: String, max_passengers: Number}>} airplane_models
*/
function displayModels(airplane_models) {
let tableBody = document.getElementById('tableBody');
clearElementChildren(tableBody);
airplane_models.forEach(model => {
for(let key in model)
{
window.alert(key)
tableBody.appendChild(createTableRow(key));
}
})
}
But this does not append the table, even the window.alert(key)
never outputs anything.
I tried to modify A code in a various way, firstly by changing @param
* @param {{name: String, max_passengers: Number}[]} airplane_models
but it gives me basically the same output. I also tried modyfing the for loop:
Object.keys(airplane_models).forEach(model => {
window.alert(model.name)
tableBody.appendChild(createTableRow(model.name));
})
Exactly the same result, no output at window.alert(model.name)