关于mui的传值方式
1、参数传值extras
1) mui 初始化: mui.init()
2) 页面跳转并传值
mui.openWindow(
{
id:
'detail'
,
url
:
'flightDetail.html'
,
extras: {
name:'mui extras 传值:',
content: cellInfo
}
})
3)新页面接收传值
//plusReady接收上一界面用extras传过来的数据
新页面:
flightDetail.html
mui.plusReady(function() {
varself=plus.webview.currentWebview();
varname=self.name;
varcontent=self.content;
if(name&&content) {
console.log('extras接收传值');
console
.log(name
+
content);
}
});
2、fire传值
fire类似于iOS的通知,能接收通知的界面必须已经存在,在mui中必须是已经存在或预加载的页面,以预加载为例:
1)mui初始化预加载
mui.init({
preloadPages:[
{
id:'flightDetail',
url
:
'flightDetail.html'
}]
});
2)事件触发 传值
//使用fire传值,页面必须已经存在或者预加载,通知传值,不存在无法接收通知
function pushToDetailWithFire ( cellInfo , type ) {
vardetailPage=plus.webview.getWebviewById('flightDetail');
mui.fire(detailPage,'detailTap', {
name:'mui fire 传值:',
content:cellInfo
});
mui.openWindow({
id: 'flightDetail',
url:'flightDetail.html'
});
function pushToDetailWithFire ( cellInfo , type ) {
vardetailPage=plus.webview.getWebviewById('flightDetail');
mui.fire(detailPage,'detailTap', {
name:'mui fire 传值:',
content:cellInfo
});
mui.openWindow({
id: 'flightDetail',
url:'flightDetail.html'
});
}
3) 接收传值
//通知
window.addEventListener('detailTap',function(event) {
console.log('fire接收传值');
varcontent=event.detail.content;
varname=event.detail.name;
console.log(name+content);
});