1

Has anyone here ever used Amplify.js for localstorage fallback on non HTML5 browsers?. I need to know if you can use it in the same way that you would localstorage for example can I get the size of my localstorage by using the length object eg amplify.store.length also can I step tru my localstorage with amplify.js via each key say for eg. amplify.store.key(i) where i is a number which is the index of the items stored?

4

1 回答 1

1

amplify.store 是对同步持久存储的抽象,因此它故意不具有与 localStorage 相同的 API。如果您不提供任何参数,那么您将返回一个包含所有键/值对的对象,您可以通过循环来解决您的两个需求。

var key,
    count = 0,
    data = amplify.store();
for ( key in data ) {
    // calculate the count
    count++;
    // or do something with the data
    console.log( key, "is", data[ key ] );
}
console.log( "There are", count, "items in the store." );
于 2011-11-07T13:08:00.243 回答