我使用PersistJS来保存会话变量,请refer here
我有以下作为我的测试代码:
<body onload='load_data();'>
<script type='text/javascript'>
// global object
var store;
function load_data() {
// load persistent store after the DOM has loaded
store = new Persist.Store('My Application');
store.set('some_key', 'this is a bunch of persistent data');
// get value from store and prompt user
store.get('some_key', function(ok, val) {
if (ok)
alert('some_key = ' + val);
});
//remove value
store.remove('some_key');
//display removed store
store.get('some_key', function(ok, val) {
if (ok)
alert('some_key = ' + val);
});
}
</script>
</body>
代码工作正常,检索设置值,但是,删除项目时,脚本崩溃,错误如下:
TypeError: this.getItem is not a function
val = this.getItem(key);
这里出了什么问题?
答案 0 :(得分:1)
获取1个参数。
这是定义:
function (key){key=this.key(key);return this.store.getItem(key);}
答案 1 :(得分:1)
persist.js中有一个错误
更改第479行
val = this.getItem(key); to val = this。 store .getItem(key);