Remembering the state of the tree view menu on refreshing the page in ruby
I have a tree view menu in ruby. I am expanding the tree and it works well. On refreshing the page it collapsesand my expansion is not seen. Please let me know if there is a way to rember the state of the tree view.
my view code:
%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_g开发者_开发技巧lob", 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"
You can use a cookie to store the actual state of your tree. When you reload the page, read the cookie and restore the expansion.
EDIT:
You need the jquery-cookie plugin, then use the persist
parameter to restore the tree expansions after reload automagically:
$(".example").treeTable({
persist: true
});
精彩评论