Не работает обертка для цикла "for". При проходе цикла каждый раз значение "singleInspTime[e].date" (и других свойств) должно быть разным, но выводимые элементы на странице одинаковы. В чем может быть ошибка?
if (singleInspTime.length != 0) {
for (var j = 0; j < singleInspTime.length; j++) {
(function(e) { // Function-wrapper for correct work of loop "for"
userInspDate.push(singleInspTime[e].date);
userInspId.push(singleInspTime[e].id);
userInspStart.push(singleInspTime[e].start);
userInspEnd.push(singleInspTime[e].end);
// Dynamically create the variables for Date Inspection Time form
var $ulInsp1 = $("<ul/>", {
id: "inspection" + singleInspTime[e].id
});
var $liInsp11 = $("<li></li>");
var $divInsp11 = $("<div/>", {
class: "item-content"
});
var $divInsp12 = $("<div/>", {
class: "item-inner"
});
var $divInsp13 = $("<div/>", {
class: "item-title label",
text: "Date"
});
var $divInsp14 = $("<div/>", {
class: "item-input"
});
var $inputInsp1 = $("<input>", {
autocomplete: "off",
type: "text",
name: "inspDate",
text: singleInspTime[e].date
});
// Dynamically create the Date inspection form
$("#Insp").append($ulInsp1);
$ulInsp1.append($liInsp11);
$liInsp11.append($divInsp11);
$divInsp11.append($divInsp12);
$divInsp12.append($divInsp13);
$divInsp12.append($divInsp14);
$divInsp14.append($inputInsp1);
// Fill the specified field "Date"
var inspDate = $('input[name="inspDate"]').val(singleInspTime[e].date);
})(j);
}
} else {
console.log("array is empty");
};