1

我使用 PersistJS 保存会话变量,请参考这里

我有以下作为我要测试的代码:

<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);

这里出了什么问题?

4

2 回答 2

1

persist.js 中有一个错误

更改第 479 行

val = this.getItem(key); 到 val = 这个。存储.getItem(key);

于 2014-12-05T21:33:12.290 回答
1

get 需要 1 个参数。


这是定义:

function (key){key=this.key(key);return this.store.getItem(key);}
于 2013-09-25T01:22:56.653 回答