How to call a function on the controller when clicking on the TabPanel? Sencha Touch 2

I have a controller and TabPanel in Sencha Touch 2, I want to call a function when an element is used in TabPanel:

TabPanel.js

Ext.define('app.view.principalTabPanel', {
    extend: 'Ext.tab.Panel',
    alias: 'widget.ptabpanel',
    config: {
        ui: 'light',
        items: [
            {
                xtype: 'container',
                itemId: 'idContnr',
                title: 'tap Me!',
                iconCls: 'bookmarks'
            }
        ],
        tabBar: {
            docked: 'bottom',
            ui: 'light'
        }
    }
});

controller.js

Ext.define('app.controller.mainController', {
    extend: 'Ext.app.Controller',
    config: {
        control: {
            "ptabpanel #idContnr": {
                tap: 'takePhoto'
            }
        }
    },
    takePhoto: function() {
        console.log('toma foto!'); // Not Working :(
    }
});
+3
source share
3 answers

Instead of listening to click events on tabs, you should listen to activeitemchange on the tab itself. See http://docs.sencha.com/touch/2-0/#!/api/Ext.tab.Panel-event-activeitemchange

+2
source

It works when listening / requesting for the html id created by Sencha "ext-tab-2".

for instance:

config: {
    control: {
        "ptabpanel #ext-tab-2": {
            tap: 'onButtonTap'
        }
    }
},

But now the problem is how to change the name "ext-tab-2" generated by Sencha Touch 2

@Borck: !.

+1

, :

tabBar: {
  id: 'myTabBar',
  items:[
    {
      id: 'myFirstTab'
    },
    {
      id: 'mySecondTab'
    },
    ...
   ]
 }
0

All Articles