簡體   English   中英

Sencha Touch 2:如何覆蓋導航視圖上的后退按鈕

[英]Sencha Touch 2: How to override back button on Navigation View

我想知道如何在導航視圖上使用后退按鈕。 我嘗試使用onBackButtonTap,但它似乎不起作用http://www.senchafiddle.com/#8zaXf

var view = Ext.Viewport.add({
            xtype: 'navigationview',
            onBackButtonTap: function () {
                alert('Back Button Pressed');
            },

            //we only give it one item by default, which will be the only item in the 'stack' when it loads
            items: [
                {
                    //items can have titles
                    title: 'Navigation View',
                    padding: 10,

                    //inside this first item we are going to add a button
                    items: [
                    {
                    xtype: 'button',
                    text: 'Push another view!',
                    handler: function() {
                    //when someone taps this button, it will push another view into stack
                    view.push({
                    //this one also has a title
                    title: 'Second View',
                    padding: 10,

                    //once again, this view has one button
                    items: [
                    {
                    xtype: 'button',
                    text: 'Pop this view!',
                    handler: function() {
                    //and when you press this button, it will pop the current view (this) out of the stack
                    view.pop();
                }
                }
            ]
        });

您提到的小提琴在計算機上的本地項目中效果很好。 由於某種原因,它在小提琴網站上不起作用。 嘗試在您的本地項目上運行它。

盡管如此,而不是使用onBackButtonTap配置,這是很好的擴展Ext.navigation.View類並重寫onBackButtonTap方法。 這樣,您將可以更好地控制整個組件。 您還希望覆蓋其他配置。 這是我要用的-

Ext.namespace('Ext.ux.so');

Ext.define('Ext.ux.so.CustomNav',{
    extend:'Ext.navigation.View',
    xtype:'customnav',
    config:{

    },
    onBackButtonTap:function(){
        this.callParent(arguments); 
        alert('back button pressed');
    }
});

這行this.callParent(arguments)將允許組件以默認方式+希望其行為的方式運行。 如果要完全覆蓋后退按鈕的行為,可以刪除此行。 嘗試兩種方式。

要使用此自定義組件,您可以使用-

launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();


        var view = Ext.create('Ext.ux.so.CustomNav', {
            fullscreen: true,

            items: [{
                title: 'First',
                items: [{
                    xtype: 'button',
                    text: 'Push a new view!',
                    handler: function() {
                        //use the push() method to push another view. It works much like
                        //add() or setActiveItem(). it accepts a view instance, or you can give it
                        //a view config.
                        view.push({
                            title: 'Second',
                            html: 'Second view!'
                        });
                    }
                }]
            }]
        });

    }

試一下。 它將為您服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM