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; }
我没有得到的结果如预期。
请看下面的结果;
是的,这是可能的。然而,当你加载页面时,你看到了什么? –
是的,你可以通过点击帖子底部的示例数据链接来查看结果。 –
毕竟,我找不到解决方案。请指导... –