在Haml中显示td标签中的数组

Displaying array in td tag in Haml

本文关键字:数组 标签 显示 Haml td      更新时间:2023-09-26

我有以下div,

 - abc.each do |gg, arr = []|
  - gg.items.each {|def| arr.push(def.values) }
  = modal(attributes: {id: 'some-modal', class: 'modal-wide'}, legacy: true) do
    = header('Item Details', attributes: {id: 'some-modal-header'})
    #graph
      - y_axis = array_values(arr)
      %table{data: {chart: 'line'}, class: 'table-hover'}
        %tbody
          %tr{data: { y_values: y_axis, x_values: [3, 10, 12, 20, 32, 35, 50, 52, 90]}}
            - y_axis.each do |y|
              %td= y
    = actions do
      %span= 'hello'
      %button.btn(data-dismiss='modal' aria-hidden='true')= 'close'

我不知道我哪里做错了。当我用这些值硬编码y_axis时,它工作得很好。当我使用上面的代码时,它跳过循环,转到"actions"。谁能给我指路啊

不清楚你想要什么,但正如我从你的代码中理解的,你想为td做一个循环:

%table{data: {chart: 'line'}, class: 'table-hover'}
  %tbody
    %tr{data: { y_values: arr, x_values: another_array}}
      - arr.each do |ar|
        %td
          = ar # this will print value of ar from loop of arr 

让我知道这是什么你正在寻找或提供我进一步的信息,以便我可以修改我的答案相应

Haml允许您轻松使用ruby迭代器和循环:

- arr.each do |element|
   %td= element

只要记住在each的行开头用-而不是=,并且你不需要写end

相关文章: