Hiding a button on pushed view and showing it when back to list view

China☆狼群 提交于 2019-12-11 04:58:29

问题


When I load my list view it has several blog posts and a refresh button on the top left.

If I tap on a list item a view is pushed with the contents of that specific post. When this view is pushed in, the refresh button is hidden.

But when I tap 'Back' to the parent list view, I'd like the refresh button to show (un-hide) - but it remains hidden.

Any idea how to make this work?

This is my View:

Ext.require(['Ext.data.Store', 'MyApp.model.StreamModel'], function() {
    Ext.define('MyApp.view.HomeView', {
        extend: 'Ext.navigation.View',
        xtype:  'homepanel',

        requires: [
            'Ext.dataview.List',
        ],

        config: {
            title:            'Home',
            iconCls:          'home',
            styleHtmlContent: true,
            navigationBar: {
                items: [
                    {
                        xtype:    'button',
                        iconMask: true,
                        iconCls:  'refresh',
                        align:    'left',
                        action:   'refreshButton',
                        id:       'refreshButtonId'
                    }
                ]
            },
            items: {
                title: 'My',
                xtype: 'list',
                itemTpl: [
                    '<div class="post">',
                        ...
                    '</div>'

                ].join(''),

                store: new Ext.data.Store({
                    model: 'MyApp.model.StreamModel',
                    autoLoad: true,
                    storeId: 'stream'
                }),
            }
        }
    });
});

and my Controller:

Ext.define('MyApp.controller.SingleController', {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            stream: 'homepanel'
        },
        control: {
            'homepanel list': {
                itemtap: 'showPost'
            }
        }
    },

    showPost: function(list, index, element, record) {

        this.getStream().push({
            xtype: 'panel',
            html: [
                '<div class="post">',
                '</div>'

            ].join(''),
            scrollable: 'vertical',
            styleHtmlContent: true,
        });

        Ext.getCmp('refreshButtonId').hide();
    }
});

回答1:


I'm not sure whether this is the best approach or not but if I were you I will use the back event of navigation view which fired when you tap the back button

So beside showPost function, you should add another control for back event like this:

'homepanel list': {
    itemtap: 'showPost'
},
stream: {
    back: 'backButtonHandler'
}

Then you can run the backButtonHandler function to show your refresh button again:

backButtonHandler: function(button){
     Ext.getCmp('refreshButtonId').show();
}

Hope it helps :)



来源:https://stackoverflow.com/questions/12761503/hiding-a-button-on-pushed-view-and-showing-it-when-back-to-list-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!