FancyTree 状态保持
FancyTree非常优秀的树控件
examples:http://wwwendt.de/tech/fancytree/
如何将树节点的选中状态保存下来,无论刷新页面还是,ajax重复请求,都保持在上一次状态呢?
FancyTree提供状态持久化保存扩展,方案如下:
https://github.com/mar10/fancytree/wiki/ExtPersist
$("#tree").fancytree({
extensions: ["persist"],
checkbox: true,
persist: {
// Available options with their default:
cookieDelimiter: "~", // character used to join key strings
cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
cookie: { // settings passed to jquery.cookie plugin
raw: false,
expires: "",
path: "",
domain: "",
secure: false
},
expandLazy: false, // true: recursively expand and load lazy nodes
overrideSource: true, // true: cookie takes precedence over `source` data attributes.
store: "auto", // 'cookie': use cookie, 'local': use localStore, 'session': use sessionStore
types: "active expanded focus selected" // which status types to store
},
[...]
});
Options
cookieDelimiter, type: {string}, default: '~'
Character used to join key strings.cookiePrefix, type: {string}, default: 'fancytree-<treeId>-'
Used to generate storage keys.cookie, type: {object}, default: use a session cookie
Options passed to$.cookieplugin (only if cookies are used; see also 'store' option).expandLazy, type: {boolean}, default: false
true: recursively expand and load lazy nodes.fireActivate, type: {boolean}, default: true
false: suppressactivateevent after active node was restored.overrideSource, type: {boolean}, default: true
true: persisted information will be used, even if source data is set totrueorfalse.
false: persisted information will only be used if source data isundefined.store, type: {string}, default: 'auto'
Storage type 'local': localStorage, 'session': sessionStorage, 'cookie': use js-cookie (or jquery-cookie ) plugin.
'auto': use sessionStorage if available, fallback to cookie.
Use 'local' (or 'cookie' with expiration settings) to store status over sessions.types, type: {string}, default: 'active expanded focus selected'
Which status types to store, separated by space.
Events
- restore
Fired after tree status is restored.
Methods
{void} tree.clearCookies(types)
Reset persistence data.
{string} [types='active expanded focus selected']
这里注意:cookiePrefix,如果不设置该值的话,每次ajax请求的tree都是不一样(非刷新页面),无法达到保持状态的效果,设置该值后,无论刷新页面还是ajax请求,都可以保持状态了。
参考文献:http://stackoverflow.com/questions/33147617/fancytree-only-loads-persist-state-after-page-refresh
cookie: { expires:365 }, 可以设置cookie的有效期,当然还有其他若干存储方式可选择
FancyTree 状态保持的更多相关文章
- Fancytree Javascript Tree的入门使用
Fancytree Javascript Tree的入门使用 一.概念----是做什么的能干什么 Fancytree是一个Javascript控件,它依赖于: <script src=" ...
- Fancytree Javascript Tree TreeTable 树介绍和使用
Fancytree是一个非常棒的Javascript控件,功能强大,文档健全.在做Javascript Tree控件选型时,主要基于以下几点选择了Fancytree 在Javascript Tree控 ...
- 【小程序分享篇 二 】web在线踢人小程序,维持用户只能在一个台电脑持登录状态
最近离职了, 突然记起来还一个小功能没做, 想想也挺简单,留下代码和思路给同事做个参考. 换工作心里挺忐忑, 对未来也充满了憧憬与担忧.(虽然已是老人, 换了N次工作了,但每次心里都和忐忑). 写写代 ...
- Http状态码之:301、302重定向
概念 301 Moved Permanently 被请求的资源已永久移动到新位置,并且将来任何对此资源的引用都应该使用本响应返回的若干个URI之一.如果可能,拥有链接编辑功能的客户端应当自动把请求的地 ...
- C# 利用性能计数器监控网络状态
本例是利用C#中的性能计数器(PerformanceCounter)监控网络的状态.并能够直观的展现出来 涉及到的知识点: PerformanceCounter,表示 Windows NT 性能计数器 ...
- 无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同。如果服务器位于远程计算机上,请检查。。。
异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Ser ...
- JavaScript var关键字、变量的状态、异常处理、命名规范等介绍
本篇主要介绍var关键字.变量的undefined和null状态.异常处理.命名规范. 目录 1. var 关键字:介绍var关键字的使用. 2. 变量的状态:介绍变量的未定义.已定义未赋值.已定义已 ...
- 【.net 深呼吸】启动一个进程并实时获取状态信息
地球人和火星人都知道,Process类既可以获取正在运行的进程,也可以启动一个新的进程.在79.77%应用场合,我们只需要让目标进程顺利启动就完事了,至于它执行了啥,有没有出错,啥时候退出就不管了. ...
- Android GridView 通过seletor 设置状态和默认状态
Android中可以通过selector控制GridView Item 的状态,而省去使用代码控制 GridView View Selector Xml文件 <?xml version=&quo ...
随机推荐
- PXE-kickstart无人值守批量装机
服务器的批量部署: 规模化:同时装配多台服务器 自动化:安装系统.配置各种服务 远程实现:不需要光盘.U盘等安装介质 PXE,Pre-boot eXcution Environment 预启动执行环境 ...
- Fix network adapter not present problem in cloned CentOS
(You can find a lot of articles on this from the internet. I just put it here for my own record.) It ...
- [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]
Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...
- 说不尽的MVVM(2) – MVVM初体验
知识预备 阅读本文,我假定你已经具备以下知识: C#.WPF基础知识 了解Lambda表达式和TPL 对事件驱动模型的了解 知道ICommand接口 发生了什么 某程序员接到一个需求,编写一个媒体渲染 ...
- thrift之TTransport层的分帧传输类TFramedTransport
帧传输类就是按照一帧的固定大小来传输数据,所有的写操作首先都是在内存中完成的直到调用了flush操作,然后传输节点在flush操作之后将所有数据根据数据的有效载荷写入数据的长度的二进制块发送出去,允许 ...
- Android 动态获取ListView的高度
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = l ...
- Bean的作用域及生命周期
指定bean的作用域通过scope属性 singleton单实例模式,从初始化容器就初始化bean,除非延迟初始化lazy-init=true prototype每次从容器获取bean是新的对象,从g ...
- 浅谈压缩感知(三十):压缩感知重构算法之L1最小二乘
主要内容: l1_ls的算法流程 l1_ls的MATLAB实现 一维信号的实验与结果 前言 前面所介绍的算法都是在匹配追踪算法MP基础上延伸的贪心算法,从本节开始,介绍基于凸优化的压缩感知重构算法. ...
- 判断输入的数是否为数字,不使用isNaN
虽然不使用 isNaN ,但使用了 Math 的一些方法. <!-- Author: XiaoWen Create a file: 2016-12-08 11:14:34 Last modifi ...
- 在ASP.NET MVC5中建置以角色为基础的授权机制
在前一篇贴文中,已探索过如何在MVC5中自定ASP.NET Identity,接下来要来试试在MVC5中如何运用 ASP.NET Identity来设定一个以 "角色"为基础的授权 ...