【问题标题】:How to end if statement in Haml?如何在Haml中结束if语句?
【发布时间】:2018-06-08 17:21:39
【问题描述】:

我想将此代码转换为 Haml,但没有“end”,整个表将成为“else”条件的一部分,而不仅仅是“tr”。如何做到这一点?

`

<% if line_item == @current_item %>
  <tr id="current_item">
<% else %>
  <tr>
<% end %>
    <td><%= line_item.quantity %>&times;</td>
    <td><%= line_item.product.title %></td>
    <td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
  </tr>

`

【问题讨论】:

  • Dzięki, próbowałem, 啤酒转换器 właśnie nie daje rady :/ podaje błędnie.

标签: if-statement haml


【解决方案1】:

通常最好在if 子句中只设置属性而不是整个标签

%tr{id: line_item == @current_item ? 'current_item' : nil}
  %td #{line_item.quantity}&times;
  %td= line_item.product.title
  %td.item_price= number_to_currency(line_item.total_price)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多