【问题标题】:Jquery Mobile "Stack" Navigation issueJquery Mobile“堆栈”导航问题
【发布时间】:2014-09-12 02:20:14
【问题描述】:

我在 Android 上使用 jQuery Mobile + Phonegap 进行页面导航时遇到问题。 我正在尝试复制 Android 堆栈导航。

情况如下:

用户未登录并在主页上

  1. 点击需要记录的“Action A”。
  2. 显示登录页面。
  3. 显示“Action A”页面。

问题是: 当用户按下返回按钮时,它应该返回主页面而不是登录页面。

但历史上的“栈”是这样的:

主要 |登录 |操作 A

我尝试过:

// return from Login page to Main:
history.back(); // $.mobile.back(); works the same way in this case.

// then go to Action A page:
$.mobile.changePage( pageA );

但是“changepage”是在“back”命令之后执行的,所以它会进入Action A页面,然后返回Login页面。

在 Android 上,这是一项非常简单的任务。 :(

【问题讨论】:

标签: android jquery-mobile cordova navigation


【解决方案1】:

你可以使用

window.history.go(-2) //Go two pages back

或者同样的方法两次

history.back(); //Go one page back
history.back(); //Go another one page back

【讨论】:

    【解决方案2】:

    只是不要调用“返回”并导航到下一页。

    在“onBackPressed”事件处理程序中检查 JQM 堆栈并使用 history.go(-2)。像这样的:

    var index = $.mobile.navigate.history.activeIndex - 1;
    if ( index >= 0 ) {
        var backStep = -1; // back one by default
        var hash;
        while ( index > 0 ) {
            hash = $.mobile.navigate.history.stack[ index ].hash;
    
            if ( hash == "#pageLogin" ) {
                backStep--;
            }
    
            index--;
        }
    
        window.history.go( backStep );
    }
    

    【讨论】:

      猜你喜欢
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 2017-07-30
      • 2014-08-26
      • 2018-03-17
      相关资源
      最近更新 更多