我可以像使用localstorage一样使用Amplify.js吗?

时间:2011-11-06 16:20:36

标签: javascript html5 polyfills

有没有人曾在非HTML5浏览器上使用Amplify.js进行本地存储回退?我需要知道你是否能以与localstorage相同的方式使用它,例如我可以通过使用长度对象获得我的本地存储的大小,例如amplify.store.length我也可以通过amplify.js来执行我的本地存储每个关键词都说例如。 amplify.store.key(i)其中i是一个数字,它是存储的项目的索引?

1 个答案:

答案 0 :(得分: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." );