duanqian9503 2017-10-18 16:34
浏览 62
已采纳

如果我正在使用laravel,如何在ajax中编写@if

Here I need a help how to write @if role in the javascript if Im using Laravel and the code in laravel as you see but I want to write the same code in the ajax section

Laravel code:

 <td class="text-center">@if ($post->adver_position==0) TOP @endif @if ($post->adver_position==1) RIGHT @endif @if ($post->adver_position==2) LEFT @endif @if ($post->adver_position==3) BOTTOM @endif</td>

Ajax:

      $('.item' + data.id).replaceWith("<tr class='item" + data.id + "'><td  class='col1'>" + data.id + "</td><td><img src='images/" + data.adver_photo + "'style='width: 50%;margin-left: 35px;border-radius: 3px;border: 1px solid #1a2732;' /></td><td>" + data.adver_title + "</td>"
  • 写回答

2条回答 默认 最新

  • doulao2916 2017-10-18 17:08
    关注

    You can not use blade from the client side, but a solution to your problem would be the next one. You can build the string that goes inside the replaceWith() function and make the comparisons from the java script, for example:

      var content = "<tr class='item" + data.id + "'> "
                    +  "<td  class='col1'>" + data.id + "</td> "
                    +  "<td><img src='images/" + data.adver_photo + "'style='width: 50%;margin-left: 35px;border-radius: 3px;border: 1px solid #1a2732;' /> </td>" 
                    +  "<td>" + data.adver_title + "</td>"
                    +  "<td> ";
    
      switch(data.adver_position) {
        case 0:
            content = content + "TOP";
            break;
        case 1:
            content = content + "RIGHT";
            break;
        case 2:
            content = content + "LEFT";
            break;
        case 3:
            content = content + "BOTTOM";
            break;
        }
    
        content = content + "</td> </tr>"
    
    
         $('.item' + data.id).replaceWith(content);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端