jquery 树视图缓存

发布于 2024-10-27 20:16:27 字数 842 浏览 2 评论 0原文

使用 jquery treeview 插件时如何应用缓存。 我还需要在刷新时显示选定的树打开。

http://jquery.bassistance.de/treeview/demo/

代码

<div class="Content">
<%= javascript_include_tag "jquery.treeview" %>
<%= stylesheet_link_tag "jquery.treeview" %>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#page_tree").treeview({
            persist: "location",
            collapsed: true
        });
    });
</script>

<ul id="page_tree">
<% @pages.each do |page| %>

  <li id ="title">
    <%= page.name %>
    <ul>
        <li><%= link_to "#{page.title}" %></li>
    </ul>
  </li>
<% end %>

How do I apply caching when using jquery treeview plugin.
I need to show selected tree open when refreshed as well.

http://jquery.bassistance.de/treeview/demo/

Code

<div class="Content">
<%= javascript_include_tag "jquery.treeview" %>
<%= stylesheet_link_tag "jquery.treeview" %>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#page_tree").treeview({
            persist: "location",
            collapsed: true
        });
    });
</script>

<ul id="page_tree">
<% @pages.each do |page| %>

  <li id ="title">
    <%= page.name %>
    <ul>
        <li><%= link_to "#{page.title}" %></li>
    </ul>
  </li>
<% end %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬花如无物 2024-11-03 20:16:27

我认为您正在寻找 persist 选项。您可以在此处查看有关可用选项的文档 http://docs.jquery.com/ Plugins/Treeview/treeview#options

示例

$(".selector").treeview({
    persist: "cookie",
   cookieId: "navigationtree"
})

更新

他们用于基于 cookie 的持久性的示例代码,该代码在演示页面上运行 - 示例 3 (基于位置的是示例 2,它似乎不起作用)如下:

Javascript

<script type="text/javascript">
    jQuery(document).ready(function() {
        $('#page_tree').treeview({
            collapsed: true,
            persist: cookie
        })    
    })
</script>

HTML

<ul id="page_tree">
<% @pages.each do |page| %>
    <li id="title"><span> <%= page.name %> </span>
    <ul>
        <li> <%= link_to "#{page.title}" %> </li>
    </ul>    
    </li>
<% end %>
</ul>

我唯一的其他建议是,如果这不起作用,请尝试静态链接到 javascript/css 文件,看看是否有效,您还需要使用 cookie.js 脚本。

<link rel="stylesheet" href="http://jquery.bassistance.de/treeview/jquery.treeview.css" />
<script type="text/javascript" src="http://jquery.bassistance.de/treeview/jquery.treeview.js" ></script>
<script type="text/javascript" src="http://jquery.bassistance.de/treeview/lib/jquery.cookie.js"></script>

I think you are looking for the persist option. You can view the documentation on what options are available here http://docs.jquery.com/Plugins/Treeview/treeview#options

Example

$(".selector").treeview({
    persist: "cookie",
   cookieId: "navigationtree"
})

Update

The example code that they use for cookie based persistence which works on the demo page - sample 3 (the location based is sample 2 and it doesn't seem to work) is as follows:

Javascript

<script type="text/javascript">
    jQuery(document).ready(function() {
        $('#page_tree').treeview({
            collapsed: true,
            persist: cookie
        })    
    })
</script>

HTML

<ul id="page_tree">
<% @pages.each do |page| %>
    <li id="title"><span> <%= page.name %> </span>
    <ul>
        <li> <%= link_to "#{page.title}" %> </li>
    </ul>    
    </li>
<% end %>
</ul>

My only other advice would be, if this does not work, try statically linking to the javascript/css files and see if that works, also you will want to use the cookie.js script.

<link rel="stylesheet" href="http://jquery.bassistance.de/treeview/jquery.treeview.css" />
<script type="text/javascript" src="http://jquery.bassistance.de/treeview/jquery.treeview.js" ></script>
<script type="text/javascript" src="http://jquery.bassistance.de/treeview/lib/jquery.cookie.js"></script>
梦里兽 2024-11-03 20:16:27
<div class="Content">
  <%= javascript_include_tag "jquery.treeview" %>
  <%= stylesheet_link_tag "jquery.treeview" %>

  <script type="text/javascript">
    jQuery(document).ready(function(){
      jQuery("#page_tree").treeview({
        persist: "location",
        collapsed: true
      });
    });
  </script>

  <ul id="page_tree">
    <% @pages.each do |page| %>

      <li id ="title">
        <%= page.name %>
        <ul>
            <li><%= link_to "#{page.title}" %></li>
        </ul>
      </li>
    <% end %>
  </ul>
<div class="Content">
  <%= javascript_include_tag "jquery.treeview" %>
  <%= stylesheet_link_tag "jquery.treeview" %>

  <script type="text/javascript">
    jQuery(document).ready(function(){
      jQuery("#page_tree").treeview({
        persist: "location",
        collapsed: true
      });
    });
  </script>

  <ul id="page_tree">
    <% @pages.each do |page| %>

      <li id ="title">
        <%= page.name %>
        <ul>
            <li><%= link_to "#{page.title}" %></li>
        </ul>
      </li>
    <% end %>
  </ul>
皇甫轩 2024-11-03 20:16:27

我知道这是一个关于过时的 jQuery 插件的老问题,但我今天才遇到这个问题。

如果您想使用 persist: 'cookie' ,您需要包含 jquery.cookie.js。否则 +/- 图标将消失并且任何操作都不起作用。

这是旧代码,因此我从 Treeview 的 git 存储库中获取了 jquery.cookie.js 以实现兼容性:
https://github.com/jzaefferer/jquery-treeview/tree/master/demo

另外,collapsed: true 似乎与持久性的想法背道而驰。

包括:

<link rel="stylesheet" href="/treeview/jquery.treeview.css" />
<script type="text/javascript" src="/treeview/jquery.treeview.js"></script>
<script type="text/javascript" src="/treeview/lib/jquery.cookie.js"></script>

JS:

jQuery(document).ready(function(){
    jQuery("#page_tree").treeview({
        persist: "cookie"
    });
});

I know this is an old question about an outdated jQuery plugin, but I just encountered this problem today.

If you want to use persist: 'cookie' you NEED to include jquery.cookie.js. Otherwise the +/- icons will disappear and nothing will work.

This is old code, so I grabbed jquery.cookie.js from the treeview's git repo for compatibility:
https://github.com/jzaefferer/jquery-treeview/tree/master/demo

Also, collapsed: true seems counter to the idea of persistence.

Include:

<link rel="stylesheet" href="/treeview/jquery.treeview.css" />
<script type="text/javascript" src="/treeview/jquery.treeview.js"></script>
<script type="text/javascript" src="/treeview/lib/jquery.cookie.js"></script>

JS:

jQuery(document).ready(function(){
    jQuery("#page_tree").treeview({
        persist: "cookie"
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文