gpt4 book ai didi

javascript - 如何从 AngularJs 中的本地存储中的键访问值?

转载 作者:行者123 更新时间:2023-11-29 19:18:24 25 4
gpt4 key购买 nike

我想使用 AngularJs 以最简单的方式访问我的本地存储中某些键的值。在 Resources --> Local Storage 我有:

Key:myKey
Value:{ "layouts":[ other_things ],"states":{ other_things },"storageHash":"fs4df4d51"}

我试过:

console.log($window.localStorage.key(0).valueOf('layouts'));
//or
console.log($window.localStorage.getItem('myKey'));

结果

myKey

最佳答案

你可以这样做:

$window.localStorage['myKey']

如果数据是字符串化的(读取:JSON.stringify)那么:

angular.fromJson($window.localStorage['myKey']);

关于javascript - 如何从 AngularJs 中的本地存储中的键访问值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com