在Ruby中刷新页面时记住树视图菜单的状态
问题描述:
我有一个红宝石树视图菜单。 我正在扩大树,它运作良好。 在刷新页面时,它会崩溃并且看不到我的扩展。 请让我知道是否有方法来重新树状视图的状态。在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"
答
您可以使用Cookie来存储你的树的实际状态。当您重新加载页面时,请阅读cookie并恢复扩展。
编辑:
您需要jquery-cookie插件,然后使用persist
参数重载自动将后恢复树扩展:
$(".example").treeTable({
persist: true
});
能否请您给我这样的链接或例子。 – ramya
@ramaya这很大程度上取决于你的实现。由于您没有提供任何有关您使用的技术的额外信息,因此很难提供建议。一些想法:每次你改变状态(展开/折叠)将其保存到cookie中时,你的树的哪些部分被展开。重新加载页面时,请使用此cookie并使用它重新展开以前扩展的树的所有部分。 – arnep
是的,这正是我需要的东西。你可以帮助这个插件。 – ramya