index.html.erbRails,是否可以根據包含餘額的表的列值更改顏色?
<% balance = 0 %>
<table align="center" width="50%" cellpadding="1" cellspacing="5">
<tr>
<td>Amount</td>
<td>Discount</td>
<td>Paid</td>
<td>Balance</td>
</tr>
<% @statements.each do |statement| %>
<tr class="tr-<%= cycle('odd', 'even') %>">
<td class="col-1"><%= statement.date %></td>
<td class="col-3"><%= statement.description %></td>
<td class="col-1"><%= number_with_precision(statement.amount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(statement.discount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(statement.paid, :delimiter => ",", :precision => 2) %></td>
<% balance += statement.amount.to_f - statement.discount.to_f - statement.paid.to_f %>
<% color = balance >= 0 ? "pos" : "neg" %>
<td class="col-1 <%= color %>"><%= number_with_precision(balance.abs, :delimiter => ",", :precision => 2) %></td>
</tr>
<% end %>
</table>
<center><p><b><%= number_to_currency(balance.abs, :unit => 'AED ', :delimiter => ",", :precision => 2) %></b></p></center>
我想有一個是平衡實體的顏色變化時餘額是正就必須表現出黑色和變負時,它必須顯示爲紅色。
這裏是我的application.css.scss
.pos { color: #000; }
.neg { color: #f00; }
我沒有得到的結果如預期。
請看下面的結果;
是的,這是可能的。然而,當你加載頁面時,你看到了什麼? –
是的,你可以通過點擊帖子底部的示例數據鏈接來查看結果。 –
畢竟,我找不到解決方案。請指導... –