在 sencha-touch-all.js 文件中找到 doTabChange函数
/**
* Updates this container with the new active item.
* @param {Object} tabBar
* @param {Object} newTab
* @return {Boolean}
*/
doTabChange: function(tabBar, newTab) {
var oldActiveItem = this.getActiveItem(),
newActiveItem;
this.setActiveItem(tabBar.indexOf(newTab));
newActiveItem = this.getActiveItem();
return this.forcedChange || oldActiveItem !== newActiveItem;
}
添加代码段,修改后如下:
/**
* Updates this container with the new active item.
* @param {Object} tabBar
* @param {Object} newTab
* @return {Boolean}
*/
doTabChange: function(tabBar, newTab) {
var oldActiveItem = this.getActiveItem(),
newActiveItem;
var index = tabBar.indexOf(newTab);
var item = this.getInnerItems()[index];
// console.log(index);
// console.log(item);
if (item.config.handler) {
if (typeof (item.config.handler) == 'string') {
eval(item.config.handler);
} else {
item.config.handler();
}
// console.log('handler');
// return ;
}
this.setActiveItem(tabBar.indexOf(newTab));
newActiveItem = this.getActiveItem();
return this.forcedChange || oldActiveItem !== newActiveItem;
}
在创建的tabPanel视图中添加 item 的属性方法 handler():
Ext.create('Ext.TabPanel', {
fullscreen: true,
tabBarPosition: 'bottom',
defaults: {
styleHtmlContent: true
},
items: [
{
title: 'Home',
iconCls: 'home',
html: 'Home Screen'.
handler:function(){
console.log("执行自定义函数功能");
}
},
{
title: 'Contact',
iconCls: 'user',
html: 'Contact Screen'
}
]
});