具有以下导轨视图(haml):
.row
.span7
%h1 Listing categories
%p
- @categories.each do |category|
.accordion-group
.accordion-heading
.accordion-toggle{"data-toggle" => "collapse", "data-target" => "##{category.path}"}= link_to category.name, "##{category.path}"
- @competitors.each do |category_path, competitors|
.accordion-body.table.collapse.in{:id => "#{category_path}"}
%table.accordion-inner
%thead
%tr
%th= "Project"
%th= "Description"
%th= "Watchers"
%th= "Forks"
%tbody
- competitors.each do |competitor|
%tr
%td
= link_to "#{competitor["html_url"]}".sub( "https:\/\/github.com\/", "" ), "#{competitor["html_url"]}"
%td
%span »
= competitor["description"]
%td
%span.badge.badge-info= competitor["watchers"]
%td
%span.badge.badge-warning= competitor["forks"]
我需要 css 类.accordion-group
来包含.accordion-heading
(在 @categories.each 循环内)和.accordion-body
(在另一个循环内:@competitors.each
循环)。
请注意,这两个.each
ruby 循环在 haml 中处于相同的“节点级别”,而它们的 css 类.accordion-heading
并且.accordion-body
必须进入.accordion-group
css 类容器。
我需要的结果 html 如下所示:
<div class="accordion-group">
<div class="accordion-heading">
<div class="accordion-body in collapse" id="collapse_id">
</div>
<div class="accordion-group">
<div class="accordion-heading">
<div class="accordion-body in collapse" id="collapse_id">
</div>
<div class="accordion-group">
<div class="accordion-heading">
<div class="accordion-body in collapse" id="collapse_id">
</div>
...
...虽然我目前得到这个错误的 html 代码:
<div class="accordion-group">
<div class="accordion-heading">
</div>
<div class="accordion-group">
<div class="accordion-heading">
</div>
<div class="accordion-group">
<div class="accordion-heading">
</div>
...
<div class="accordion-body in collapse" id="collapse_id">
<div class="accordion-body in collapse" id="collapse_id">
<div class="accordion-body in collapse" id="collapse_id">
...
我找不到缩进haml的正确方法...