简体   繁体   English

在没有NavigationView的情况下如何处理sencha touch应用程序中的后退按钮?

[英]How to handle back button in sencha touch application without NavigationView?

I have googled, but all the useful articles are all describing how to handle the back button in NavigationView, but I just use the common view like below. 我已经用谷歌搜索过,但是所有有用的文章都描述了如何在NavigationView中处理后退按钮,但是我只使用下面的通用视图。

Ext.define('emall.view.MyPage', {
    extend: 'Ext.Container',
    alias: 'widget.mypage',

    requires: [
        'emall.view.topplus',
        'Ext.TitleBar',
        'Ext.Button',
        'Ext.Toolbar'
    ],

I am do changes on the existing app, so I can not change the base architecture. 我正在对现有应用程序进行更改,因此无法更改基本体系结构。 So I am wondering how to handle the back button? 所以我想知道如何处理后退按钮?

I know below way can capture the back button event.(I added the below method to app.js) 我知道以下方法可以捕获后退按钮事件。(我将以下方法添加到app.js中)

if (Ext.os.is('Android')) {
    document.addEventListener("backbutton", Ext.bind(onBackKeyDown, this), false);

    function onBackKeyDown(eve) {

        eve.preventDefault();
        //do something
        alert('back button pressed');
        history.back();  

    }
}

But what can I do in the method onBackKeyDown ? 但是我可以使用onBackKeyDown方法什么? Since this event will be fired when I click the back button no matter which page I am staying. 由于无论我停留在哪个页面上,单击后退按钮都会触发此事件。 So I can not go to the previous page like Ext.Viewport.animateActiveItem('xxxx') since I do not know the current page I am staying. 因此,由于我不知道我停留的当前页面,所以无法进入Ext.Viewport.animateActiveItem('xxxx')之类的上一页

If I can get the current page name, I can handle it like below. 如果可以获得当前的页面名称,则可以按以下方式进行处理。

if(currentpage=='xxx')
            Ext.Viewport.animateActiveItem('profile', {
                type : 'slide',
                direction:'left'
            });

Use this code: 使用此代码:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {if (navigator.userAgent.match("Android"))
{       document.addEventListener("backbutton", onBackKeyDown, true);  }  

}

function onBackKeyDown(e) {
    if (window.location.hash === "#splashviewRoute") {      
        navigator.app.exitApp();
    }   
    else  {
        window.history.back();
    }
}

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

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