Javascript 在Haml中显示td标记中的数组

Javascript 在Haml中显示td标记中的数组,javascript,html,ruby,haml,Javascript,Html,Ruby,Haml,我有下面的部门 - 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

我有下面的部门

 - 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_轴时,它工作得很好。当我使用上面的代码时,跳过循环并转到“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

只需记住以
开头的每行
都是
-
,而不是
=
,并且您不需要写
结束

您好。您已经实现了上述代码;已经写好了。您能否给出所有变量的示例值,以及您希望使用Haml实现的最终HTML(不是Haml)是什么?@vanga:如果您为我们提供数组和另一个数组的对象内容,将更有帮助。还有简单的HTML,请按您的意愿进行。很抱歉造成混淆。我已经更新了说明我正在尝试做什么。谢谢