-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
62 lines (62 loc) · 1.76 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var utils = {
//合并数组
arrayMerge : function (array1, array2) {
$.each(array2, function(k, v) {
array1[k] = v;
});
return array1;
},
//获取本地存储
getStorage : function(key, returnObject, isSession) {
if(isSession == true) {
var value = sessionStorage.getItem(key);
} else {
var value = localStorage.getItem(key);
}
if(returnObject == true && value != "") {
value = JSON.parse(value);
} else if(returnObject == true ) {
value = {}
}
return value;
},
//获取本地存储列表
getStorageList : function(returnObject, isSession) {
if(isSession == true) {
var storage = sessionStorage;
} else {
var storage = localStorage;
}
var storageList = {};
for(var i=0;i < storage.length; i++){
var key = storage.key(i);
var value = storage.getItem(key);
if(returnObject == true && value != "") {
value = JSON.parse(value);
} else if(returnObject == true ) {
value = {}
}
storageList[key] = value;
}
return storageList;
},
//设置本地存储
setStorage : function(key, value, isSession) {
if(typeof(value) == "object") {
//TODO 字符串下标转换失败
value = JSON.stringify(value);
}
if(isSession == true) {
sessionStorage[key] = value;
} else {
localStorage[key] = value;
}
return true;
},
isEmptyObject: function (obj){
for(var n in obj){
return false;
}
return true;
}
}