您的位置:首页 > 产品设计 > UI/UE

mui关于页面间传值的方法

2016-03-25 18:36 471 查看
2016/3/25
方法0:fire传值
mui.openWindow({
url:'road_lineWindCar.html',
id:'road_lineWindCar.html',
waiting:{
autoShow:false
},
extras:{
car:this.getAttribute("car"),   //这里的值可以是你在函数体里的具体的值,我这里是把这些值写在(li)标签里的属性
hcCityName:this.getAttribute("hcCityName"),
qcStoreName:this.getAttribute("qcStoreName")
}
})

在预加载里写
mui.plusReady(function(){
var car = plus.webview.currentWebview().car;
var hcCityName = plus.webview.currentWebview().hcCityName;
var qcStoreName = plus.webview.currentWebview().qcStoreName;
})

方法1:mui实现页面间传值:fire传值  这种方法传值,有可能传不过去

第一步:要有目标页面
var roadLinePage = plus.webview.getWebviewById('choose_car.html');
第二步:要有自定义事件 其中getQcCity就是事件
mui.fire(roadLinePage,'getQcCity',{
qcCityName:cityName,
qcCityId:cityId
});
第三部:要在目标页面监听事件getQcCity
window.addEventListener('getQcCity',function(event){
//获得事件参数
var id = event.detail.qcCityId;//获取传过来的值
document.getElementById("qcCity_").value=id;
console.log("取车城市"+id);
freshCarTable();//要执行的函数
});

方法2:
本地存储--存储json格式的数据
localStorage.setItem(name, JSON.stringify(value));

var obj = localStorage.getItem(name);
return mui.parseJSON(obj);

/**
* 本地存储Utils
*/
var localStorageUtils = {
setParam: function (name, value) {
if (value) {
localStorage.setItem(name, JSON.stringify(value));
}
},
getParam: function (name) {
var obj = localStorage.getItem(name);
return mui.parseJSON(obj);
},
removeParam: function (key) {
return localStorage.removeItem(key);
}
}

H5+中本地存储使用--
方法:3:
获取应用存储区中保存的键值对的个数
var foo = plus.storage.getLength();
修改或添加键值(key-value)对数据到应用数据存储中
void plus.storage.setItem(key, value);
通过键(key)检索获取应用存储的值
var foo = plus.storage.getItem(key);
通过key值删除键值对存储的数据
void plus.storage.removeItem(key);
清除应用所有的键值对存储数据
void plus.storage.clear();
获取键值对中指定索引值的key值
var foo = plus.storage.key(index);
var keyNames=[];
var values=[];
var numKeys=plus.storage.getLength();
for(var i=0; i<numKeys; i++) {
keyNames[i] = plus.storage.key(i);
values[i] = plus.storage.getItem(keyNames[i]);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mui-手机端js