I'm trying make if/elseif statement in my script inside an Table and I did, but I don't understand why data does not get displayed. When I check in browser (as you can see in Screenshot number 2). I also check debugger statement and everything seems fine as you can see in Screenshots number 1. Is there something wrong with my Syntax? Can anyone point me in right direction? thanks in advance :)
Script:
var ResultString = "";
$.each(result, function (i, e) {
ResultString +=
'<tr>' +
'<td>' + e.Varenummer + '</td>' +
'<td>';
if (e.Status == "Sendt") {
'<i class="fa fa-arrow-right" aria-hidden="true"></i>' +
e.Status
} else if (e.Status == "Under behandling") {
'<i class="fa fa-check" aria- hidden="true"></i>' +
e.Status
}
'</td>' +
'</tr>'
});
And i have same thing in my Razor page , which working fine and i want same thing in my Script :
@foreach (var rma in Model)
{
<tr>
<td>
@{
if (rma.Status == "Sendt")
{
<i class="fa fa-arrow-right" aria-hidden="true"></i> @rma.Status
}
else if (rma.Status == "Under behandling")
{
<i class=" fa fa-exclamation-circle" aria-hidden="true"></i> @rma.Status
}
else if (rma.Status == "Blive behandlet")
{
<i class="fa fa-check" aria-hidden="true"></i> @rma.Status
}
}
</td>
</tr>
}
The problem is that you do not append this string to your ResultString
variable.
Here is a quick fix
var ResultString = "";
$.each(result, function (i, e) {
ResultString += '<tr>' +
'<td>' + e.Varenummer + '</td>' +
'<td>';
if (e.Status == "Sendt") {
ResultString += '<i class="fa fa-arrow-right" aria-hidden="true"></i>' +
e.Status;
} else if (e.Status == "Under behandling") {
ResultString += '<i class="fa fa-check" aria- hidden="true"></i>' +
e.Status;
}
ResultString += '</td>' +
'</tr>';
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.