簡體   English   中英

使用Jquery / Ajax在表內創建if語句的語法-ASP.NET MVC

[英]Syntax for an if statement inside an Table Using Jquery/Ajax - ASP.NET MVC

我正在嘗試在表中的腳本中執行if / elseif語句,但確實這樣做了,但我不明白為什么數據無法顯示。 當我在瀏覽器中簽入時(如屏幕截圖2所示)。 我還檢查了調試器語句,一切似乎都很好,如屏幕快照1所示。我的語法有問題嗎? 誰能指出我正確的方向? 提前致謝 :)

SC

在此處輸入圖片說明


腳本:

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>'
});

我在Razor頁面上也有同樣的東西,它工作正常,並且我在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>
}

問題是您沒有將此字符串附加到ResultString變量。

這是一個快速修復

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>';
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM