I have a piece of jQuery that constructs the inner HTML of a custom Version History table. To fill each table row with elements I use jQuery's load for each row. However this function is asynchronous, which messes up my table... Code:
//fill tblBody
for (var i = 0; i < xArr.length; i++) {
tblBody += "<tr>";
var xDiv = $("<div>");
xDiv.load(xAppWebUrl + "/Lists/dlWerkinstructies/Forms/DispForm.aspx?ID=" + xItemId + "&VersionNo=" + xArr[i] + " table.ms-formtable", function () {
var xTbl = $(this).find("table.ms-formtable");
var tr = xTbl.find("tr");
$(tr).each(function () {
var row = $(this);
var xFieldValue = $.trim(row.find("td:eq(1)").text());
tblBody += "<td>" + xFieldValue + "</td>";
});
});
tblBody += "</tr>";
}
What happens is that tblBody begins with all <tr></tr>
followed by all <td>
tags. Any way how I get make the loads synchronous? Also other possible solutions are welcome!! Thanks in advance.