0

我正在创建一个应用程序,在该应用程序中我需要一个会话来存储用户 ID,稍后我可以使用它来从 datadase 中获取数据。我是 phonegap Android 应用程序的新手,对会话一无所知。所以任何人都可以给我一些示例或链接,我可以从中了解如何创建会话和使用它。提前致谢。这是js代码:

ftable=results.rows.item(i).from_table;//from database i am getting to know from which table to call for the select data option in dropdown list
if(ftable.indexOf('#')=='-1'){
from_Table=ftable;
}else{
//**in the from_table there is query which will need session data **//
//  from_Table="(select i.industry_id, i.industry_name, i.deleted, i.comp_code from user_industry_asso cuia, industry i where i.industry_id = cuia.industry_id and cuia.user_id = '1' order by i.industry_name)";
from_Table="";
split_table=ftable.split('#');


alert("Length: "+split_table.length);
for(var k=0;k<split_table.length;k++){
    alert("After split: "+split_table[k]);
    if(k%2==1){
        from_Table +=eval(split_table[k]);
        alert("For loop if condition: "+from_Table);
    }else{
        from_Table +=split_table[k];
        console.log("Else condition: "+from_Table);
    }
}   
}
var select_optionData1="select "+optionName+"," +optionValue+" from "+from_Table+" alias where deleted='0' and comp_code='1' order by "+optionName;
tx.executeSql(select_optionData1,[]);//will get the data from the table and store in array object which will be called later to create a dropdownlist

这是我在 html 文件中创建的会话:

var userid='1';
 window.sessionStorage.setItem('ls_userid',userid);

 var userId = window.sessionStorage.getItem('ls_userid');
4

1 回答 1

2

对于商店会话,您可以使用 localStorage 按照此链接

window.localStorage.setItem('ls_userid',userid);
var userid = window.localStorage.getItem('ls_userid');
console.log(userid);
于 2013-08-17T10:04:08.167 回答