具有以下Rails視圖(HAML):嵌套循環HAML獲得 「摺疊引導-collapse.js」 Rails內部意見工作正常
.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
紅寶石環路,是在Haml的「節點級別」,而他們的CSS類.accordion-heading
和.accordion-body
必須到.accordion-group
CSS類容器。
的resoulting 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">
...
我找不到縮進的正確方法哈姆...
「@ categories」和「@ competators」的大小始終相同嗎? – matt