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

发布于 2024-12-14 03:15:41 字数 247 浏览 5 评论 0原文

这里有人曾经使用过 Amplify.js 在非 HTML5 浏览器上进行本地存储回退吗?我需要知道您是否可以像使用 localstorage 一样使用它,例如我可以通过使用长度对象来获取本地存储的大小,例如 amplify.store.length 我也可以逐步实现我的 localstorage 与 amplify.js 通过每个键例如说。 amplify.store.key(i) 其中 i 是一个数字,它是存储项目的索引?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-12-21 03:15:41

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

amplify.store is an abstraction over synchronous persistent storage, so it intentionally does not have the same API as localStorage. If you don't provide any parameters, then you will get back an object of all key/value pairs, which you can loop over to solve both of your needs.

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." );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文