日期:2014-05-16  浏览次数:20420 次

Extjs实现快捷键CTRL+TAB对Tabpanel进行Tab切换

?

// 注册ctrl+tab组合键到keymap
var keyMap=new Ext.KeyMap(Ext.getBody(),[{  
			    	  key:[9], //tab
			    	  ctrl:true,
			    	  fn:function(){handleCtrlTab();}
			    	  scope:this,
			    	  defaultEventAction: "stopEvent"
			      }]
			);  
keyMap.enable();

// 实现tabpanel的切换
function handleCtrlTab()
{
	var targetTabPanel = Ext.getCmp('mytabpanel');
	var curTab = targetTabPanel.getActiveTab();
	var curIndex = targetTabPanel.items.indexOf(curTab);
	var nextTabIndex = curIndex + 1;
	var itemSize = targetTabPanel.items.length;
	if (nextTabIndex >= itemSize)
	{
		nextTabIndex = 0;
	}
	
	var nextTab = targetTabPanel.items.itemAt(nextTabIndex);
	targetTabPanel.activate(nextTab);
	
	// 10ms进行聚焦,保证连续响应ctrl+tab
	nextTab.focus(false, 10);  
}
?