导航到另一个页面后如何保留数组 [英] How to keep an array after navigation away to another page

查看:82
本文介绍了导航到另一个页面后如何保留数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我声明了一个数组:

Ok, so I have an array declared as so:

 var names_Array = [];

然后我创建一个列表,该列表由上述数组中的元素组成.声明为:

Then I am creating a list and that list is composed of the elements in the above array. It is declared as so:

 var names_List = new WinJS.Binding.List(names_Array);

根据我第一页中的情况.我正在将项目添加到此列表中,如下所示:

Based on a condition in my first page. I am adding items to this list, as so:

 if (condition) {
     names_List.push({ name: "xxx", image: "image/xxx.png", ClientID: "xxxx" });
 }

然后,我要移至另一页,我的目标是当我回来时仍将添加的任何元素保留在那里.我知道,到目前为止,由于以下原因,该列表为空:

Then I am moving to another page and my goal is for when I come back to have any of the elements which were added still there. I am aware, as of now that when I go back, the list is empty because of the line:

var names_Array = [];

所以我的问题是,当我离开并返回时,有什么方法可以保留列表中的项目.我意识到我需要在第一页中附加一个if条件,以确定这是否是该页上的第一次,或者用户是否走开了再回来.像这样:

So my question is, is there any way to keep the items of the list, when I move away and come back. I realise I need an additional if condition in the first page to determine if this is the first time on the page or if the user has gone away and come back. Something like:

if (first){
    if(condition){
    sort out list;
    }
}
else{
    re-sort out list
}

有什么想法吗?

推荐答案

您可以尝试多种解决方案:

There are a number of solutions you could try:

  1. 将信息作为会话对象存储在服务器上,并在每次访问的页面上提供数据.

  1. store the information as a session object on the server and provide the data in the page each tie you visit.

将数据存储在 localStorage .

将数据存储在 cookie 中.

正确的答案在很大程度上取决于您的应用程序的详细信息,因此我建议研究每个选项并选择最合适的选项.

The right answer depends too much on details of your application, so I suggest researching each of this options and choosing the best fit.

这篇关于导航到另一个页面后如何保留数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆