[英]Getting value from localstorage back to it original state
I am trying to get a value I set in localStorage back to its original state.我正在尝试将我在 localStorage 中设置的值恢复到其原始状态。 I saved newLocation(40.7033127,-73.979681);
我保存了newLocation(40.7033127,-73.979681);
to the localStorage as move1
and I am getting it with localStorage.getItem("move1");
到 localStorage 作为move1
,我用localStorage.getItem("move1");
. . As you can see it's a map coord so it should not be showing as localStorage.getItem("move1")
it should automatically return the value of move1
.正如你所看到的,它是一个地图坐标,所以它不应该显示为localStorage.getItem("move1")
它应该自动返回move1
的值。
My question is how can I get the value instead of the code showing me localStorage.getItem("move1");
我的问题是如何获取值而不是代码显示我localStorage.getItem("move1");
? ?
If I understand your question correct, it seems the problem exists because one always gets a String back from localStorage and you want to get it back in whatever type you saved it.如果我理解您的问题是正确的,那么问题似乎存在,因为人们总是从 localStorage 取回一个字符串,而您希望以您保存的任何类型取回它。
Then you should do: localStorage.setItem("move1", JSON.stringify(sam)));
那么你应该这样做: localStorage.setItem("move1", JSON.stringify(sam)));
And for the other one: localStorage.setItem("move2", JSON.stringify(wise)));
对于另一个: localStorage.setItem("move2", JSON.stringify(wise)));
And then you could do: new Location(JSON.parse(localStorage.getItem("move1")), JSON.parse(localStorage.getItem("move2")));
然后你可以这样做: new Location(JSON.parse(localStorage.getItem("move1")), JSON.parse(localStorage.getItem("move2")));
If that is what you want.如果那是你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.