asker
asker
  • 发布:2015-04-16 21:16
  • 更新:2018-03-07 09:58
  • 阅读:6900

关于beforeback 有几个疑问, 请帮忙解答一下.

分类:MUI

现在我是一个列表页A到详情页B, 查看了文档中的beforeback方法, 但是屡次无法实现, 我想问下

mui.init({  
    beforeback: function(){  
        //获得列表界面的webview  
        var list = plus.webview.getWebviewById('list');  
        //触发列表界面的自定义事件(refresh),从而进行数据刷新  
        mui.fire(list,'refresh');  
        //返回true,继续页面关闭逻辑  
        return true;  
    }  
});

plus.webview.getWebviewById('list'); 这个是不是列表页? 这个列表页的id怎么取值?
代码中的"refresh"是需要自己写function的吗?
这个function是在B页面还是A页面调用?
或者能不能提供1个更具体一些的例子, 因为卡在这里.... 多谢~

2015-04-16 21:16 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

getWebviewById里边的参数是你创建webview传入的id
参考:http://dcloudio.github.io/mui/javascript/#customevent

  • Kenzgoingon

    亲测,beforeback并不能在iOS屏幕边缘右滑这一关闭手势之后执行监听函数

    2018-05-07 10:44

ccclubs

ccclubs

最后怎么解决的?能否提供一下,QQ号578646533

UESTC_SKY

UESTC_SKY

@DCloud_MUI_FXY beforeback出发的函数我需要用户选择后再确定是否返回,如何做?代码如下:
beforeback:function(){
var uploadedAttach = JSON.parse(localStorage["oTempAttachInfo"]);
var totalAttach = mui(".goodsImage img");
if(uploadedAttach.length != totalAttach.length){
plus.nativeUI.confirm("您还有未上传的图片,请点击右上角上传按钮上传",function(e){
if(e.index == 0){
return false
}
else {
return true;
}
},null,["马上去上传","我不上传了"]);
}
}
把return放到里面就不能起效果啊,如何解决????
感觉plus.confirm有点异步的感觉……

UESTC_SKY

UESTC_SKY

我换一种思维来解决,先让mui.back()失效,即让before back返回false,然后再在confirm的回调中来处理是否返回(通过关闭webview的方式),代码如下:
beforeback:function(){
var uploadedAttach = JSON.parse(localStorage["oTempAttachInfo"]);
var totalAttach = mui(".goodsImage img");
if(uploadedAttach.length != totalAttach.length){
plus.nativeUI.confirm("您还有未上传的图片,请点击右上角上传按钮上传",function(e){
if(e.index == 0){
}
else{
plus.webview.close(plus.webview.currentWebview());
}
},null,["马上去上传","我不上传了"]);
}
else{
plus.webview.close(plus.webview.currentWebview());
}
return false;
}

专注写bug

专注写bug - 不积跬步,无以至千里

你使用了fire表示refresh事件为自定义事件,你需要在上级页面监听refresh,在监听函数中调用plus.webview.currentWebView().reload()完成刷新

该问题目前已经被锁定, 无法添加新回复