2011-09-23 54 views
0

我有一個紅寶石樹視圖菜單。 我正在擴大樹,它運作良好。 在刷新頁面時,它會崩潰並且看不到我的擴展。 請讓我知道是否有方法來重新樹狀視圖的狀態。在Ruby中刷新頁面時記住樹視圖菜單的狀態

我的視圖代碼:

%table.treeTable 
%thead 
%th 
    All: 
    = link_to "Expand", "#", :class => "all_action_expand" 
    = "/" 
    = link_to "Collapse", "#", :class => "all_action_collapse" 
%th 
    = link_to "Check", "#", :class => "check_all" 
    = "/" 
    = link_to "Uncheck", "#", :class => "uncheck_all" 


%tbody 
- Ic.make_tree(@ics).values.each do |root| 
    %tr{:id => root.tree_id, :class => "root"} 
    %td= root.root_name 
    - if show_check_boxes 
     %td= check_box_tag "ic_glob", root.tree_id, false, :class => "ic_parent" 
    - root.suites.each do |suite| 
    %tr{:id => suite.tree_id, :class => "child-of-#{root.tree_id}"} 
     %td= suite.suite_name 
     - if show_check_boxes 
     %td= check_box_tag "ic_glob", suite.tree_id, false, :class => "ic_parent" 
    - suite.children.each do |case_item| 
     %tr{:id => case_item.tree_id, :class => "child-of-#{suite.tree_id}"} 
     %td= case_item.case_name 
     - if show_check_boxes 
      %td= check_box_tag "ic_glob", case_item.tree_id, false, :class => "ic_parent" 
     - case_item.children.each do |ic| 
     %tr{:id => ic.id, :class => "child-of-#{case_item.tree_id}"} 
      %td= link_to ic.name, edit_ic_path(ic.id) 
      - if show_check_boxes 
      %td= check_box_tag "ic_ids[]", ic.id, false 
    /Execute the tree table javascript (hackish) 
    = javascript_tag "$('.treeTable').treeTable({persist:true})" 
/Need some Ic javascript to (cascading selects, etc.) 
    = javascript_include_tag "pages/ic" 
    = javascript_include_tag "jquery.cookie" 

回答

0

您可以使用Cookie來存儲你的樹的實際狀態。當您重新加載頁面時,請閱讀cookie並恢復擴展。

編輯:

您需要jquery-cookie插件,然後使用persist參數重載自動將後恢復樹擴展:

$(".example").treeTable({ 
    persist: true 
}); 
+0

能否請您給我這樣的鏈接或例子。 – ramya

+0

@ramaya這很大程度上取決於你的實現。由於您沒有提供任何有關您使用的技術的額外信息,因此很難提供建議。一些想法:每次你改變狀態(展開/摺疊)將其保存到cookie中時,你的樹的哪些部分被展開。重新加載頁面時,請使用此cookie並使用它重新展開以前擴展的樹的所有部分。 – arnep

+0

是的,這正是我需要的東西。你可以幫助這個插件。 – ramya