简体   繁体   English

jQuery Mobile App-导航并不总是有效

[英]Jquery Mobile App - navigation does not work always

My Single Page Application contains a number of data-role="page" and each page loads one script where pageshow and pagebeforeshow are intercepted (such as below). 我的单页应用程序包含许多data-role =“ page”,并且每个页面都加载一个脚本,在该脚本中将截获pageshowpagebeforeshow (例如,下面)。

In pageshow I fill one html tag and in pagebeforeshow I empty it. pageshow中,我填充了一个html标签,在pagebeforeshow中,我将其清空。

> $(document).delegate("#page1", "pageshow",        
function (e, data) {   
> filling page1Content ... 
}
> 
> $("#page1").on("pagebeforeshow", 
function(e, data) {
>   $("#page1Content").empty(); 
});

Backbutton is managed this way: 后退按钮的管理方式如下:

function onBackKeyDown() {
    if($.mobile.activePage.attr('id') == 'page2'){
        $.mobile.pageContainer.pagecontainer("change",
        "#page1");
    }else if ($.mobile.activePage.attr('id') == 'page3') {
        $.mobile.pageContainer.pagecontainer("change",
        "#page2");
    }
...

Navigation works properly as well as backbutton but after a while of surfing it gets broken, missing somepage or loading the same page and then it continues working properly. 导航和后退按钮一样正常工作,但是经过一段时间的浏览后,导航被破坏,丢失某些页面或加载同一页面,然后继续正常工作。

Questions: 问题:

  • How can I solve my Problem? 我该如何解决我的问题?

  • Is there any wrong pattern/function in the way I am managing the event? 我管理活动的方式是否有任何错误的模式/功能?

  • Are pages stored in some sort of Stack? 页面是否存储在某种堆栈中? (if so, how can I check it)? (如果是,该如何检查)?

I am using JQM 1.4, Cordova 3.4, Android 我正在使用JQM 1.4,Cordova 3.4,Android

My solution was to refactor my Single Page Application as a Multipage one. 我的解决方案是将单页应用程序重构为页应用程序。

Everything started working superfast and with no problem during the navigation. 一切开始超快运行,并且在导航过程中没有问题。

I do not suggest to use SPA to someone who is new with this environment. 我不建议对这种环境的新手使用SPA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM