javascript
  • html
  • ruby-on-rails
  • 2015-08-28 32 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丁代碼我認爲它可以幫助你做出一些邏輯。 –

    相關問題