I am working on this project where I need to building html from this object. There a a lot of loops and counter and wanted to see if there is a better way to do this
Any suggestions/comments are greatly appreciated to improve the code further. Thanks.
full function https://jsfiddle.net/tjmcdevitt/xLbusdk3/10/
$.each(question.MeetingPollingParts, function (index, value) {
if (value.MeetingPollingPartsTypeId === MeetingPollingPartsTypeId.Image) {
$.each(value.MeetingPollingPartsValues, function (index, parts) {
console.log(parts);
HTML += "<div class='row'>";
HTML += "<div class='col-md-12'>";
HTML += "<div class='form-group'>";
let strImage = "data:" + parts.FileType + ";base64," + parts.FileData;
console.log(strImage);
HTML += "<img src='" + strImage + "' />";
HTML += "</div>";
HTML += "</div>";
HTML += "</div>";
});
}
if (value.MeetingPollingPartsTypeId === MeetingPollingPartsTypeId.Answer) {
$.each(value.MeetingPollingPartsValues, function (index, parts) {
if (parts.MeetingPollingPartsValuesTypeId === MeetingPollingPartsValuesTypeId.Radio) {
htmlthTable += "<th>";
htmlthTable += parts.QuestionValue;
htmlthTable += "</th>";
countRadio = countRadio + 1;
}
});
}
console.log(countRadio);
if (value.MeetingPollingPartsTypeId === MeetingPollingPartsTypeId.RowQuestion) {
$.each(value.MeetingPollingPartsValues, function (index, parts) {
if (parts.MeetingPollingPartsValuesTypeId === MeetingPollingPartsValuesTypeId.MultipleChoiceGrid) {
htmltrTable += "<tr><td>";
htmltrTable += parts.QuestionValue;
htmltrTable += "</td>";
for (var i = 1; i <= countRadio; i++) {
htmltrTable += "<td>";
htmltrTable += "<input type='radio'>";
htmltrTable += "</td>";
}
htmltrTable += "</tr>";
}
});
}
});