动态数组到本地存储/ jstorage? [英] dynamic array to local storage/jstorage?
问题描述
我每隔10秒将值推送到我的数组中,这是由div上的innerHTML显示的。
I am pushing values in to my array every 10 seconds which is being displayed by innerHTML on a div.
Onreload或访问我想要的其他网页显示已推送的内容和当前正在推送的内容。
我已经完成了当地的stroage和jstorage教程。
Onreload or on visit to some other web page I want to display the already pushed content and the content being pushed presently. I have gone through local stroage and jstorage tutorials.
这就是我正在做的精确=:
This is what I am doing precisely=:
localStorage.setItem('names', xyz);
我知道如何存储一个变量,但是当我们更新动态数组/ 10秒时每10秒推送一次数据。即使我去其他链接,我也会设置并获得动态数组。
I know how to store one variable,but what when we have a dynamic array being updated/10sec and data being pushed in it every 10 seconds.how do I set and get this dynamic array even when I go to some other link.
如果您对我的代码感兴趣: http://jsfiddle.net/vCcnB/
If you are interested in my code:http://jsfiddle.net/vCcnB/
UPDATE 1 ----用于简化(如果您已理解,请忽略。)
这是我div中显示的内容.Page1表示页面和0,10,20表示时间。
UPDATE 1----for simplification(ignore if you have understood.) This is what is being displayed in my div.Page1 indicates the page and 0,10,20 indicates time.
@ 10 seconds----[page1,0]
[page1,10]
@20 seconds-----[page1,0]
[page1,10]
[page1,20]
now a click to some other page.
@10 seconds----[page1,0]
[page1,10]
[page1,20]
[page2,0]
[page2,10]
now a click to some other page.
@20 seconds----[page1,10]
[page1,20]
[page2,0]
[page2,10]
[page3,0]
[page3,10]
[page3,20]
推荐答案
您可以使用 json对象
,例如,
localStorage.setItem('names', {'ABC','XYZ'}); //and so on
或 json string
喜欢
var json={'ABC','XYZ'};
localStorage.setItem('names', JSON.stringify(json)); //and so on
获取现有的项试试这个,
console.log(localStorage.getItem('names'));
阅读 https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Storage
这篇关于动态数组到本地存储/ jstorage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!