This is a bit tricky to explain, I'll try my best.
I have a website based on Spring that uses static HTML pages with AJAX and jQuery. I want to present some info in an HTML page that will always vary in size.
I have a table such as this: (don't mind the terrible design)
So, depending on the number of countries and users returned from the API, I want to have different number of rows.
I'm currently using a jQuery function to inject the HTML code after submitting this form:
Such as this:
$('#stats').submit((event) => {
event.preventDefault();
$.ajax({
url: '/api/stats/' + $(event.currentTarget).serialize(),
type: 'GET',
success(msg) {
// language=HTML
$('#result').html(`
<div class="container">
<h2>Country stats:</h2>
<div class="panel panel-group">
<table>
<thead>
<tr>
<th>Country</th>
<th>Users</th>
</tr>
</thead>
<tbody>
<tr> <!-- I want to generate here the right amount of rows -->
<td>Test</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
</div>`);
},
error() {
$('#result').html("<div class='alert alert-danger lead'>ERROR</div>");
},
});
The response received from the API looks like this:
{
"countries":
[{"data":xx,"users":xx},
{"data":xx,"users":xx}],
"other data":
[whatever]
}
And so on.
How can I render N rows if N is the size of the countries array?