Amazon UI 学习笔记
2015-08-17 17:26
435 查看
LocalStorage 并没有提供过期时间接口,只能通过存储时间做比对实现
var store = $.AMUI.store;
var storeWithExpiration = {
set: function(key, val, exp) {
store.set(key, {val:val, exp:exp, time:new Date().getTime()});
},
get: function(key) {
var info = store.get(key)
if (!info) {
return null;
}
}
};
storeWithExpiration.set(‘foo’, ‘bar’, 1000);
setTimeout(function() {
console.log(storeWithExpiration.get(‘foo’));
}, 500) // -> “bar”
setTimeout(function() {
console.log(storeWithExpiration.get(‘foo’));
}, 1500) // -> null
如果获取这些的值回事什么样?
store.get(skey)
//如果本地没有则返回undefined 本地有就是Object {val: Object, exp: 300000, time: 1439801294712}
var store = $.AMUI.store;
var storeWithExpiration = {
set: function(key, val, exp) {
store.set(key, {val:val, exp:exp, time:new Date().getTime()});
},
get: function(key) {
var info = store.get(key)
if (!info) {
return null;
}
if (new Date().getTime() - info.time > info.exp) { return null; } return info.val
}
};
storeWithExpiration.set(‘foo’, ‘bar’, 1000);
setTimeout(function() {
console.log(storeWithExpiration.get(‘foo’));
}, 500) // -> “bar”
setTimeout(function() {
console.log(storeWithExpiration.get(‘foo’));
}, 1500) // -> null
如果获取这些的值回事什么样?
store.get(skey)
//如果本地没有则返回undefined 本地有就是Object {val: Object, exp: 300000, time: 1439801294712}
相关文章推荐
- 线段树专题—HDU 4027 Can you answer these queries?
- easyui-validatebox 验证两次密码是否输入一致
- How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs
- How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs
- How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs
- hadoop序列文件读与写 (SequenceWriteReadFile)
- Easyui combobox如何默认选中第一项???
- [leetcode][deque] Sliding Window Maximum
- IOS UI简单的控件位置/尺寸/旋转变换
- PAT 1041. Be Unique (20)
- PAT 1085. Perfect Sequence (25)
- UICollectionView
- 09流程控制,while,for,continue,break
- EasyUI 中combotree 默认不能选择父节点
- easyui datagrid 单元格编辑 自动聚焦 、全选
- UILabel使用自定义字体
- UIAutomator API浅析
- POJ 1019 Number Sequence (循环递增序列的的第K个值)
- POJ 1679 The Unique MST(判断最小生成树_Kruskal)
- 【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计