如何存储项目在本地存储在jqueryMoblie [英] how to store items in local Storage in jqueryMoblie

查看:143
本文介绍了如何存储项目在本地存储在jqueryMoblie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4页,如A,B,C和D. A有水果名字,B有花名称.4页面流动如下

 <  -  
A - > C
- > D
B - > C
/ pre>

当我通过A去C时,C有水果名称与复选框,当我通过B到C,C有花名称与复选框。 C有书Button.When我们点击book按钮数据去D页。



我们需要的是当我去(A - > C)。我们选择3个水果。下一步回到B,得到C.We选择2花
然后点击BookOrder我们需要显示totla 5 items.In D页



我的问题只是如何显示上次选择的项目..



我们尝试了以下内容:



在页面C

  function imagebackRedriect(){
var myStuffArray = [];
var itemName;
$('input:checked')。each(function(){
$ this = $(this);
checkboxidforvalidation = this.id;
itemName = $ ).closest('tr')。children('td:eq(2)')。text();
myStuffArray.push([itemName]);
localStorage [myStuffLocalArray] = JSON .stringify(myStuffArray);
sessionStorage.setItem(forAllGridItems,myStuffArray);
});
TempItems = JSON.parse(localStorage [myStuffLocalArray]);
var GetallElements + = sessionStorage.getItem(forAllGridItems);
}



我们尝试当我们选择复选框数据添加到JSON或Session时,离开并返回C数据将被删除。



请指导我

解决方案

在更新列表时,尝试使用 JSON.parse(sessionStorage.getItem(forAllGridItems));



我不太清楚为什么要使用 sessionStorage localStorage



您选择使用哪个存储选项,大多数资源推荐您使用 localstorage.setItem(key,value ); ,并且在处理字符串以外的任何数据类型时,请记住使用 JSON.stringify()


I have 4 pages like A,B,C and D. A have fruits names, B have flowers names .4 Pages flow like this

 <--   
A -->C
       -->D 
B -->C

When i went to C through A,C have fruits names with check box,and When I Went to C through B,C have flowers names with check box.C have book Button.When we Click book button data go to D page.

What we need is When i go to (A-->C).We select 3 fruits .Next back to B and got C.We Select 2 flowers Then Click on BookOrder We need to Show totla 5 items.In D page

My problem is only how to show Last selected items..

We tried The following:

in Page C

function imagebackRedriect( ) {
var myStuffArray =[];
 var itemName;
     $('input:checked').each(function () {
              $this = $(this);
              checkboxidforvalidation=this.id;
              itemName= $(this).closest('tr').children('td:eq(2)').text();
            myStuffArray.push([itemName]);  
            localStorage["myStuffLocalArray"] = JSON.stringify(myStuffArray);
           sessionStorage.setItem("forAllGridItems", myStuffArray);
       });
              TempItems = JSON.parse(localStorage["myStuffLocalArray"]);
        var GetallElements += sessionStorage.getItem("forAllGridItems");
    }

We tried When we select checkbox Data Add to JSON or Session, but when we leave and come back to C Data Will be removed.

Please guide me

解决方案

Try using JSON.parse(sessionStorage.getItem("forAllGridItems")); in the last line when you are updating the list.

I am quite not sure why you would want to use both sessionStorage and localStorage

Which ever storage option you choose to use, it's recommended by most resources that you go with localstorage.setItem("key", "value");, and remember to use JSON.stringify() when working with any data types other than strings.

这篇关于如何存储项目在本地存储在jqueryMoblie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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