javascript
  • html
  • ruby-on-rails
  • 2015-08-28 31 views 0 likes 
    0

    我在帮助程序方法中运行一个循环。在rails项目中显示帮助程序中行的隐藏

    这给了我一个结果,如6行后关闭行,然后为接下来的6个项目创建另一行,并继续。

    现在我想有另一种情况,如果有超过2行,我不想显示第三或第四循环,而不是我想要一个链接/按钮,说更多的显示和点击显示其他项目。

    这里的代码

    part_child_option. each_slice(6) do | six_o| 
        html += "<div class = 'row'>" 
        six_o.each do |o| 
        html += "<div class='col-sm-2 uno_part_wrapper'>" 
        html += "<label class = 'p_name' for='#{attr_name}'>" 
        html += image_tag o.photo(:small), class: "tick_option_img" 
         html += "</label>" 
         html += "</div>" 
        end 
         html += "</div>" 
        end 
    html.html_safe 
    

    这个任何想法。我们可以把条件,如count>2,隐藏剩余的行和点击显示全部。

    回答

    1

    请详细说明您的问题,并从视图中显示一些代码。问题是你想要做什么,当你点击“更多+”按钮(想打开新的索引页面或通过ajax加载剩余的行)。

    根据可用的描述,我建议你把link_to more, items_path和重定向在所有项目的索引页上。

    更新: 您的每行包含6个元素,默认情况下有2行意味着12个元素在那里。所以,用each_slice_with_index替换你的each_slice循环,并把if条件。

    e.g

    part_child_option. each_slice_with_index(6) do | six_o , i| 
        if i <= 1  
         html += "<div class = 'row'>" 
         six_o.each do |o| 
         html += "<div class='col-sm-2 uno_part_wrapper'>" 
         html += "<label class = 'p_name' for='#{attr_name}'>" 
         html += image_tag o.photo(:small), class: "tick_option_img" 
          html += "</label>" 
          html += "</div>" 
         end 
          html += "</div>" 
        elsif i == 2 
         show link here 
         html += same code as above with hidden class added 
        else 
         html += same code as above with hidden class added 
        end 
    end 
    

    我建议采取行,从而以较小的方法的一些代码,使这个帮手简单。

    +0

    想要显示更多点击节目上的剩余行。 – Suraj

    +0

    加载我想只显示两行和一个显示更多按钮,并点击该按钮,剩下的行。 这是我正在尝试的 '$(window).load(function(){(“。class1> div”)。next()。next()。css('visibility','hidden' );'然后 '$('。button_click')。click(function(){ ); }) 这是行不通的。我怎么才能添加显示更多的按钮,只有两行以上的地方? 我只是在我的页面上添加一个锚然后它涉及到所有的地方 希望现在很清楚 – Suraj

    +0

    我更新了你的exis丁代码我认为它可以帮助你做出一些逻辑。 –

    相关问题