簡體   English   中英

在Rails項目中顯示助手中的行隱藏

[英]show hide of rows inside a helper in a rails project

我正在使用輔助方法運行循環。

這給了我一個結果,例如在關閉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 ,隱藏剩余的行,然后單擊全部顯示。

請詳細說明您的問題,並從視圖中顯示一些代碼。 問題是,當您單擊“更多+”按鈕(想要打開新的索引頁或僅通過ajax加載剩余的行)時要做什么。

根據可用的描述,我建議您在所有項目的索引頁面上放置一個link_to more, items_path並重定向。

更新:您的每一行包含6個元素,默認情況下有2行意味着有12個元素。 因此,更換您的each_slice帶環each_slice_with_index ,把if條件。

例如

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

我建議對一些較小的方法使用行制作代碼,以使此幫助程序變得簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM