页面js数据缓存

页面js数据缓存

ID:40908280

大小:41.50 KB

页数:6页

时间:2019-08-10

页面js数据缓存_第1页
页面js数据缓存_第2页
页面js数据缓存_第3页
页面js数据缓存_第4页
页面js数据缓存_第5页
资源描述:

《页面js数据缓存》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、页面js数据缓存  将js数据比如ajax请求来的数据缓存起来是很早就开始做的事情,原来是用一个全局变量__data来存储,现在基于jquery写的两种实现方式。cache这种方式是很普遍的一种实现方式,icache是将数据缓存到dom中,在使用的过程中依赖json.js可以缓存多种类型的数据。cache和icache有一个差别是icache需要检验key和value,这是因为将数据写入dom时需要将不同类型的数据先转换为字符串,这也是可能需要json.js的原因。/** *cache. *paged

2、atacacheincache. */(function($){$.cache={};$.extend($.cache,{map:{},push:function(key,value){$.cache.map[key]=value;},remove:function(key){delete($.cache.map[key]);},clear:function(){$.cache.map={};},get:function(key){return$.cache.map[key];}});})(jQuer

3、y);/** *icache. *pagedatacacheindom.  */(function($){$.icache={};$.extend($.icache,{validStr:function(str){returntypeof(str)=='string'?true:false;},data:{containerId:'icacheContainer'},enable:function(){if($('#'+$.icache.data.containerId).length!=0)retu

4、rn;varcontainer=$('

').attr('id',$.icache.data.containerId).hide();$('body').append(container);},getContainer:function(){$.icache.enable();return$('#'+$.icache.data.containerId);},push:function(key,value){if(!$.icache.validStr(key)

5、

6、!$.icache.validS

7、tr(value))return;varcontainer=$.icache.getContainer();vare=container.find('#'+key);if(e.length==0)e=$('

').attr('id',key).appendTo(container);e.html(value);},get:function(key){return$.icache.getContainer().find('#'+key).html();},remove:function(key)

8、{$.icache.getContainer().find('#'+key).remove();},clear:function(){$.icache.getContainer().empty();}});})(jQuery);

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。