While using the $.each
function in jQuery, I am retrieving data and adding it to a table in the following manner:
$.each(segment, function (index, innerSegment) {
var tr;
tr = $('<tr/>');
tr.append("<td>" + segment[i].Airline.AirlineName + "</td>");
tr.append("<td>" + segment[i].ArrivalTime + "</td>");
tr.append("<td>" + segment[i].Origin + "</td>");
tr.append("<td>" + segment[i].DepartureTime + "</td>");
tr.append("<td>" + segment[i].Destination + "</td>");
tr.append("<td>" + segment[i].Duration + "</td>");
tr.append("<td>" + segment[i].publishedFare + "</td>");
$('#tableId').append(tr);
}
Although I am successfully receiving data from the $.each
loop, all the data is getting appended one after the other.
I would like the data to be displayed as shown in this example on jsfiddle: https://jsfiddle.net/1pbso9jt/
The structure of my table is as follows:
<table id="tableId">
<tr>
</tr>
</table>