应用存储

应用存储/包括运行时变量、配置信息等
牛刀小试
运行时变量
设置运行时变量
获取运行时变量
app.setGlobalVariable("天王盖地虎", "宝塔镇河妖");
app.getGlobalVariable("天王盖地虎", function(res){
	app.alert("返回值类型:"+typeof(res)+"\n结果:"+ JSON.stringify(res));
});
	
持久化保存配置信息
设置配置信息
读取配置信息
读取所有配置信息
移除指定配置信息
//设置以及读取配置信息
app.setting.set("name","aotuman");
app.setting.set("sex","female");
app.setting.get("name","默认值",function(res){
	app.alert(res);
});
//读取所有配置信息
app.setting.getAll(function(res){
	app.alert(res);
});
//移除指定配置信息
app.setting.remove("sex");
	app.setting.get("sex","默认值",function(res){
	app.alert(res);
});
	
html5存储-SessionStorage
sessionStorage的存储
sessionStorage的读取
sessionStorage的移除
示例代码
//sessionStorage的存储、读取、移除
sessionStorage.setItem("天王盖地虎", "宝塔镇河妖");
app.alert(sessionStorage.getItem("天王盖地虎"));
sessionStorage.removeItem("天王盖地虎");
	
html5存储-localStorage
localStorage的存储
localStorage的读取
localStorage的移除
示例代码
//localStorage的存储、读取
localStorage.setItem("天王盖地虎", "宝塔镇河妖");
app.alert(localStorage.getItem("天王盖地虎"));
localStorage.removeItem("天王盖地虎");
//读取所有配置信息
app.setting.getAll(function(res){
	app.alert(res);
});
//移除指定配置信息
app.setting.remove("sex");
	app.setting.get("sex","默认值",function(res){
	app.alert(res);
});
	
html5存储-SQLite
打开或创建数据库
执行非查询sql
执行查询sql
//打开或创建数据库,参数分别为"数据库名称","版本","大小"
app.database.open("test", "1.0", 1000000);
//执行非查询sql: create,drop,insert,update,delete. 支持批量
// app.database.executeNonQuery(database, sql, success, fail);
var mydata = app.database.open("test", "1.0", 1000000);
app.database.executeNonQuery(mydata, [
        'DROP TABLE IF EXISTS DEMO',
        'CREATE TABLE IF NOT EXISTS DEMO (id unique, data)',
        'INSERT INTO DEMO (id, data) VALUES (1, "First row")',
        'INSERT INTO DEMO (id, data) VALUES (2, "Second row")'
   		],function(){
   		 },function(res){
});      
//执行查询
 var mydata = app.database.open("test", "1.0", 1000000);
 var str = "";
 app.database.executeQuery(mydata,'SELECT * FROM demo',function(tx, results){
 		var len=results.rows.length;
 		for(var i = 0; i < len ; i++){
 		 str= str + "\n" + results.rows.item(i).data;
 		}
  		app.alert(str);
    },function(res){
 });