监听选项卡项目在Sencha中单击

hey*_*jii 2 listener tabpanel sencha-touch-2

在我的应用程序中,我正在使用一个包含5个项目的选项卡面板.每个项目在卡片布局中添加了大约6个面板.当我在选项卡项目中的最后一个面板时,我需要通过单击底部选项卡面板(有点类似于iOS中的常规选项卡视图控制器)返回到初始面板.我找到了一些我在这里找到的解决方案,但它似乎只有在我在标签之间切换时才有用.实际上我想在同一个标​​签图标上听点击事件.我怎样才能做到这一点?

小智 5

我已经解决了你的问题.我认为这正是你想要的.希望这可以帮助.如果不是这样,请发表评论.

1).查看(MyTabPanel1.js)

    Ext.define('MyApp.view.MyTabPanel1', {
    extend: 'Ext.tab.Panel',
    config: {

            scrollable: 'vertical',
             items:
            [
                {
                   xtype: 'panel',
                   id:'cardpanel1',
                   title: 'Tab1',              
                   layout: 'card',
                        items: [
                            {  
                                html: "First Item",
                                items:
                                [
                                {
                                    xtype: 'button',
                                    text: 'Forward',
                                    handler: function() {
                                    Ext.getCmp('cardpanel1').setActiveItem(1);
                                    console.log('Going to Second Item');
                                    }
                                }
                                ]
                            },
                            {
                                html: "Second Item",
                                items:
                                [
                                {
                                    xtype: 'button',
                                    ui: 'confirm',
                                    text: 'Go back',
                                    handler: function() {
                                    Ext.getCmp('cardpanel1').setActiveItem(0);
                                    console.log('Going to First Item');
                                    }
                                }
                                ]
                            }

                        ]               

                },

                {
                    xtype: 'panel',
                    title: 'Tab2',
                    scrollable: true,
                    items: [
                        {
                            xtype: 'button',
                            margin: 10,
                            ui: 'action',
                            text: 'Tab2'
                        }

                    ]
                },
                {
                    xtype: 'panel',
                    title: 'Tab3',
                    scrollable: true,
                    items: [
                        {
                            xtype: 'button',
                            margin: 10,
                            ui: 'action',
                            text: 'Tab3'
                        }
                    ]
                }

            ]
        }

    });
Run Code Online (Sandbox Code Playgroud)

2).控制器(MainController.js)

    Ext.define('MyApp.controller.MainController', {
        extend: 'Ext.app.Controller',
        config: {
            control: {

                "tabpanel #ext-tab-1":{  //ext-tab-1 is the id for the 1st tab generated by Sencha
                   tap: 'ontap'
                }            
            }
        },

        ontap: function (){
        console.log('inside controller');
        Ext.getCmp('cardpanel1').setActiveItem(0);
        }

    });
Run Code Online (Sandbox Code Playgroud)