简体   繁体   English

Ruby / Rails / HTML / HAML-创建一个两列表,第一列单元格跨越动态行数

[英]Ruby/Rails/HTML/HAML - create a two column table with first column cells spanning dynamic number of rows

I am trying to create an HTML table in HAML that has a first column where each cell spans a dynamic number of rows based on the number of values in an Array which will be split across multiple cells in the second column. 我正在尝试在HAML中创建一个具有第一列的HTML表,其中每个单元格根据基于Array中值的数量跨越动态行数,该数组将在第二列中拆分为多个单元格。 So for example, if Array.size == 2, then the first cell in the first column will have rowspan=2 and the second column will have Array[0] in the first row and Array[1] in the second row and the column 1 value will span both rows. 因此,例如,如果Array.size == 2,则第一列的第一单元格的rowpan = 2,第二列的第一行的Array [0]和第二行的Array [1],第1列的值将跨越两行。 The HAML code I wrote to do this is as follows: 我为此编写的HAML代码如下:

- @array1.each do |item|
    %tr
    %td{:rowspan => "#{item.array.size}"}= time_tag(item.created_at)
    - item.array.each do |item|
      %td= "#{item.name}" 
      %tr

The issue I am having is that HAML automatically inserts one set of row tags after each loop through the second block which results in the second item.name ending up in the first column of the second row instead of in the second column of the second row. 我遇到的问题是,在每次循环通过第二个块之后,HAML都会自动插入一组行标记,这将导致第二个item.name最终出现在第二行的第一列而不是第二行的第二列。 How can I fix my code to make the table work as I described it? 如何修复代码以使表按我描述的那样工作?

I don't know if I understand you but I think it could work with the following code: 我不知道我是否了解您,但我认为它可以与以下代码一起使用:

%table
- @products.each do |item|
  %tr
    %td{:rowspan => "#{item.array.size}"}= "#{item.name}"
    %td
      - item.array.each do |item2|
        %tr
          %td= "#{item2.name}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM