Sencha Touch - When switching Items using setActiveItem(), how can I access the Back button?

邮差的信 提交于 2019-12-11 18:10:12

问题


Problem:

I switch Panels using setActiveItem() according to question-answer on this link

App.views.viewport.getActiveItem().setActiveItem(App.views.Panel, { type: 'slide', direction: 'left' });

Everything works fine, but how can I access my back button?

I suspect that theres only 1 back button, and I have to change his properties (text, handler). How Can I do that?

Thank you, Shlomi.

P.S- when thinking about it, I have to modify all the bar properties - its title as well.


回答1:


I will try to answer this question referencing the previous question about panels.

First add a back button to your panel's top bar.

initComponent: function () {
      Ext.apply(this, {
       dockedItems: [{
            xtype: "toolbar",
            title: "Ingressos",
            items:[{
                 xtype: 'button',
                 text: 'Back',
                 handler: function () {

                 }
            }]
       }],
       items: [Mobz.views.IngressosList]
    });
   Mobz.views.Ingressos.superclass.initComponent.apply(this, arguments);
}

After that when user goes to next page, access the back button and change it's handler(I won't prefer to change handler, I prefer build a stack mechanism to go bacward but it is your choice :) ).

Mobz.views.viewport.getActiveItem() //panel

Mobz.views.viewport.getActiveItem().dockedItems.items[0] // toolbar

You are seeking back button;

Mobz.views.viewport.getActiveItem().dockedItems.items[0].items.items[0] // back button

Mobz.views.viewport.getActiveItem().dockedItems.items[0].title // toolbars title



回答2:


{
    xtype: 'button',
    text: 'Back',
    handler: function () {
        App.views.viewport.setActiveItem([The panel you want to go], {type: 'slide', direction: 'right'});
    }
}

Add a button in your "App.views.viewport" panel.



来源:https://stackoverflow.com/questions/8315079/sencha-touch-when-switching-items-using-setactiveitem-how-can-i-access-the

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