0

我希望每个循环的第一个元素是“活动的”,并用一个活动的 css 类包装它。我试过这个,但现在每个项目都处于活动状态。艾做错了什么?

#myCarousel.carousel.slide
  .carousel-inner
    - @cities.each do |city|
      - city.activities.find_all_by_homepage_city(true).each do |b|
        - b.attachments.each_with_index do |a, index|
          - if index=0 
            .active.item
              = link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
              .carousel-caption
               %h4 yep 1
          - else 
            .item
              = link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
              .carousel-caption
                %h4 yep 2 

谢谢..remco

4

1 回答 1

4

你有错别字,应该if index == 0不是if index = 0

无论如何,如果我想做你正在做的事情,我会做以下事情

#myCarousel.carousel.slide
  .carousel-inner
    - @cities.each do |city|
      - city.activities.find_all_by_homepage_city(true).each do |b|
        - b.attachments.each_with_index do |a, index|
          %div{ :class => "#{index == 0? 'active item' : 'item'}" }
            = link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
            .carousel-caption
              %h4
                = index == 0 ? 'yep 1' : 'yep 2'
于 2013-02-15T11:39:48.223 回答