0

我有以下一段代码,它打印分隔列中的项目列表。

- if @product.type_id == 2
      %th.order_invoice_cell.each.count
        #{l(:item)}
      - @product.products.each do |p|
        %th.order_invoice_cell
          #{l(:item)}

但是所有的列都被命名为 item、item、item。现在,如果我想提及 item1 item2 item3 等数字。我怎样才能做到这一点。

4

2 回答 2

1

改为使用each_with_index。所以你可以做@product.products.each_with_index do |p,index|

于 2013-08-05T08:44:35.950 回答
1

我不知道,你#{l(:item)}在做什么。但你可以使用这个:

- if @product.type_id == 2
      %th.order_invoice_cell.each.count
        #{l(:item)}
      - @product.products.each_with_index do |p, index|
        %th.order_invoice_cell
          = "item #{index + 1}"

它将为您提供第 1 项、第 2 项等等...谢谢

于 2013-08-05T08:55:36.197 回答