ext TabPanel相关

  • 在使用Ext.TabPanel时,经常会用到tabchange事件,但却发现第一次渲染的时候,这个事件执行了两次,原因是因为使用了activeItem而不是activeTab,把activeItem:0,换成activeTab:0 就没事了,具体的原因俺粗略的看了一下TabPanel的源码,没有在源文件中找到activeItem属性,因为忙,所以就没继续找,哪位知道的,回复一下!

activeItem 是从tabpanel的items集合来说的.
而activeTab又是另外一个层次.
[code="js"]
//这个是TabPanel里面的一部分源代码,可以看出来他的默认布局采用Cardlayout
this.setLayout(new Ext.layout.CardLayout({
deferredRender: this.deferredRender
}));
//...........

this.layout.setActiveItem(item);//在tabpanel里面就是通过设置cardlayout的这个方法来显示那个panel
[/code]

而在CardLayout里面这个方法的源代码又是这样的
[code="js"]
/**
* Sets the active (visible) item in the layout.
* @param {String/Number} item The string component id or numeric index of the item to activate
*/
setActiveItem : function(item){
item = this.container.getComponent(item);//从布局容器里面获得这个 item
if(this.activeItem != item){
if(this.activeItem){
this.activeItem.hide();
}
this.activeItem = item;
item.show();
this.layout();
}
}
[/code]

activeItem是定义在CardLayout中的。