how to call a function on a controller when Tapping on TabPanel? Sencha Touch 2

谁说我不能喝 提交于 2019-12-07 15:38:10

问题


I have a controller and a TabPanel in Sencha Touch 2, I want to call a function when an element is tapped on the 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 :(
    }
});

回答1:


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




回答2:


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

for Instance:

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

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

@Borck: thanks!.




回答3:


You can assign IDs to the tab bar buttons by adding this configuration to the tab panel:

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


来源:https://stackoverflow.com/questions/10519731/how-to-call-a-function-on-a-controller-when-tapping-on-tabpanel-sencha-touch-2

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