在ruby中刷新页面时记住树视图菜单的状态

时间:2011-09-23 13:06:29

标签: javascript ruby-on-rails treeview jtree

我在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"

1 个答案:

答案 0 :(得分:0)

您可以使用cookie来存储树的实际状态。重新加载页面时,请阅读cookie并恢复扩展。

修改

您需要jquery-cookie插件,然后使用persist参数在自动重新加载后恢复树扩展:

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