1***@qq.com
1***@qq.com
  • 发布:2016-10-17 11:16
  • 更新:2016-10-17 11:23
  • 阅读:1456

求助!求助!H5+ storage 能不能存储对象,为什么我获取的是null

分类:HTML5+

var person = {};
person.name = 'white';
person.age = '12';
person.sex = '男';
plus.storage.setItem('person',person);

.......

plus.storage.getItem('person'); //这样可以吗

2016-10-17 11:16 负责人:无 分享
已邀请:
赵梦欢

赵梦欢 - 专注前端,乐于分享!

将对象转成字符串存,用的时候取出来,如:

/**  
 * 本地存储  
 */  
app.storage = (function () {  
    var storage = {};  
    var store = window.plus ? plus.storage : localStorage;  
    storage.isEmpty = function (key) {  
        var val = store.getItem(key);  
        if(val === null){  
            return true  
        }  
        return false  
    }  
    storage.set = function (key, value) {  
        store.setItem(key, JSON.stringify(value));  
    };  
    storage.get = function (key, type) {  
        var val = store.getItem(key);  
        type = type || 'json';  
    if (val && type === 'json') {  
            return JSON.parse(val)  
        }  
        return val;  
    };  
    storage.remove = function (key) {  
        store.removeItem(key);  
    };  
    storage.clear = function () {  
        store.clear();  
    };  
    return storage  
}())

该问题目前已经被锁定, 无法添加新回复