我只想输出一个锚定在这里。如果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
有帮助吗?

解决方案

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

其他提示

好了,所以我认为,我们正在检查其没有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" }

对不起 - 我误解你在做什么?还以为你做一个包括哪些内容?上的阵列,但它是一个字符串,...: - )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top