可以在 Phonegap 中使用 window.localStorage 传递数组吗?
目前,我正在尝试使用 window.localStorage 在两个页面之间的 Phonegap 中传递多维数组。在 main.js 中,我使用
var storage = window.localStorage;
storage.setItem("information", myArray);
window.location = "summary.html";
在文件summary.js 中,我使用:
var storage = window.localStorage;
var myArray = storage.get("information");
当我运行此命令时,myArray 仅返回未定义。我知道它在调用 window.location = "summary.html";
之前已完全定义。我现在对问题的最佳猜测是,存储或检索数组时存在错误,至少是我这样做的方式。你不能通过 localStorage 传递数组吗,还是我做错了什么?
Currently, I'm trying to pass a multidimensional array in Phonegap between two pages with window.localStorage. In main.js, I use
var storage = window.localStorage;
storage.setItem("information", myArray);
window.location = "summary.html";
And in the file summary.js, I use:
var storage = window.localStorage;
var myArray = storage.get("information");
When I run this, myArray only returns undefined. I know that it is fully defined right before I call window.location = "summary.html";
. My best guess to the problem right now is that there is an error in either storing or retrieving an array, at least the way I'm doing it. Can you not pass Arrays through localStorage, or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在获取项目或将项目保存到本地存储时,我通常使用
JSON.stringify
和JSON.parse
。我相信目前大多数实现仅支持字符串。I typically use
JSON.stringify
andJSON.parse
when getting or saving items to local storage. I believe most implementations only support strings at the moment.