Cocos2d 本地数据保存接口封装

设置key,value进行保存:

    setLocalStorageString:function(key,value){
        key="LS:"+key;
        if(typeof this[key] === 'undefined' || undefined != this[key]){
            sys.localStorage.setItem(key, value);
            this[key]=value;
        }
    },

读取本地保存的key对应的value:

    getLocalStorageString:function(key){
        key="LS:"+key;
        if(typeof this[key] === 'undefined')
            this[key]=sys.localStorage.getItem(key);
        return this[key];
    },

删除本地key对应的value:

    deleteLocalStorageString:function(key){
        key="LS:"+key;
        if(typeof this[key] === 'undefined' || undefined != this[key]) return;

        sys.localStorage.removeItem(key);
        delete this[key];
    },

猜你喜欢

转载自blog.csdn.net/zhenyu5211314/article/details/78357175