1

我只想在这里输出一个锚点。如果 current_page 在数组中,我会得到两个(.html 和 -nf.html)。如果它不在数组中,我会得到与数组中的项目一样多的锚点。

我正在使用StaticMatic

- if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

    // loop through the pre-flash array and if current page matches, add -nf
    - page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
    - page_options[:pre_flash].each do |each_string|

        - if current_page.include? each_string
            %li 
                %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                    Next
        - else
            %li
                %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
                    Next
4

2 回答 2

2
unless current_page.include? the_string

编辑:

如果你希望你的第一个发现是唯一的,你可以打破每个循环。但是现在这看起来有点奇怪,因为无论发生什么,您都在遍历一个数组并在第一个元素之后中断。我在解决你的问题吗?

options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
page_options[:pre_flash].each do |each_string|
  if current_page.include? each_string
    %li 
    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
    # This is the last ancor
    break
  else
    %li 
    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
    # This is the last ancor
    break
  end
end
于 2009-12-01T00:35:17.380 回答
1

好的,所以我认为我们正在检查 page_options[:current_index] 都不是 current_page 的子字符串。

if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

found_item = false

// loop through the pre-flash array and if current page matches, add -nf
- page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
- page_options[:pre_flash].each do |each_string|

    - if current_page.include? each_string
            found_item = true
            %li 
                    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                            Next

# do whatever you need to get out of the staticmatic block...

    - if !found_item

            %li
                    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }

抱歉 - 我误解了你在做什么......以为你在做一个包含?在一个数组上,但它是一个字符串...... :-)

于 2009-12-01T00:36:04.897 回答