如何获取 Darts Storage 中的所有对象

发布于 2025-01-01 07:05:21 字数 279 浏览 7 评论 0原文

正如 this SO 中提到的,这是获取存储在本地存储中的所有对象的方式:

for (var key in localStorage){
   console.log(key)
}

如何我会在 Dart 中做同样的事情吗?

As mention in this SO, this is the way t get all objects stored in a localstorage:

for (var key in localStorage){
   console.log(key)
}

How would I do the same in Dart?

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

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

发布评论

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

评论(1

若水微香 2025-01-08 07:05:21

您可以以几乎相同的方式从 Dart 的 本地存储 获取键和值

Element log = document.query('#log');
log.nodes.clear();
for(int i=0; i<window.localStorage.length; i++) {
    var elm = new Element.tag("p");
    var key = window.localStorage.key(i);
    elm.innerHTML = "key ${key} value ${window.localStorage.getItem(key)}"; 
    log.nodes.add(elm);
}

You can get the keys and values from Dart's local storage in almost the same way

Element log = document.query('#log');
log.nodes.clear();
for(int i=0; i<window.localStorage.length; i++) {
    var elm = new Element.tag("p");
    var key = window.localStorage.key(i);
    elm.innerHTML = "key ${key} value ${window.localStorage.getItem(key)}"; 
    log.nodes.add(elm);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文