尝试在 HAML 中制作表格,我有以下内容:
%table
%tbody
%tr
%th{:rowspan => 2} Name
%th{:class => "leftBorderS", :colspan => 5} Monday
%th{:class => "leftBorderS", :colspan => 5} Tuesday
%th{:class => "leftBorderS", :colspan => 5} Wednesday
%th{:class => "leftBorderS", :colspan => 5} Thursday
%th{:class => "leftBorderS", :colspan => 5} Friday
%th{:class => "leftBorderS", :colspan => 5} Saturday
%tr
- 6.times do
%th{:class => "leftBorderS"} A
%th{:class => "leftBorderD"} B
%th{:class => "leftBorderD"} C
%th{:class => "leftBorderD"} D
%th{:class => "leftBorderD"} E
- @data.each do |row|
%tr
- row.each do |column|
%td{:class => "leftBorderD"}= column
CSS类:
table {
border-collapse: collapse;
}
th {
border: 1px solid #ccc;
padding: 0.2em;
}
.weeklyReview .leftBorderS {
border-left: 1px solid black;
text-align: center;
}
.weeklyReview .leftBorderD {
border-left: 1px dotted orange;
}
.weeklyReview .rowGray {
background-color: gray;
}
.weeklyReview .rowWhite {
background-color: white;
}
Rails 控制器传递的示例数据:
@data = [["adam", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["boy", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["charles", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["david", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["echo", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["foxtro", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["gamma", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["helio", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5], ["indigo", 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5],]
问题出现在代码的最后一部分。我希望每个人都有%tr
不同的颜色。目前默认是灰色的,但这仍然意味着其他的都必须是白色的,所以我只做了两个类来在两者之间切换)。另外为了分隔日期,只有某些%td
s 将具有实心左边框,否则,它们将具有虚线边框。
对于 HAML 标记:
- 你如何跨过每一行?
- 您如何仅将
n
第一个实例应用于数据单元格?
我主要是在寻找语法,因为它可以应用于数据单元格、行、列或任何需要解析或单步执行的东西。