jquery 树视图缓存
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在寻找
persist
选项。您可以在此处查看有关可用选项的文档 http://docs.jquery.com/ Plugins/Treeview/treeview#options示例
更新
他们用于基于 cookie 的持久性的示例代码,该代码在演示页面上运行 - 示例 3 (基于位置的是示例 2,它似乎不起作用)如下:
Javascript
HTML
我唯一的其他建议是,如果这不起作用,请尝试静态链接到 javascript/css 文件,看看是否有效,您还需要使用
cookie.js 脚本。
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#optionsExample
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
HTML
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.我知道这是一个关于过时的 jQuery 插件的老问题,但我今天才遇到这个问题。
如果您想使用 persist: 'cookie' ,您需要包含 jquery.cookie.js。否则 +/- 图标将消失并且任何操作都不起作用。
这是旧代码,因此我从 Treeview 的 git 存储库中获取了 jquery.cookie.js 以实现兼容性:
https://github.com/jzaefferer/jquery-treeview/tree/master/demo
另外,
collapsed: true
似乎与持久性的想法背道而驰。包括:
JS:
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:
JS: