2010-12-02 18 views
0

當我想以應對用戶在網格上選擇行,我用這個:我怎麼能把一個響應用戶在選項卡中Ext.TabPanel

var grid = new Ext.grid.GridPanel({ 
    region: 'center', 
    ... 
}); 
grid.getSelectionModel().on('rowselect', function(sm, index, rec){ 
    changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index) 
}); 

我怎麼能裝上與標籤相同的功能?是這樣的:

var modules_info_panel = new Ext.TabPanel({ 
    activeTab: 0, 
    region: 'center', 
    defaults:{autoScroll:true}, 
    listeners: { 
     'tabclick': function(tabpanel, index) { 
      changeMenuItemInfoArea(menuItemModules,'you clicked the tab with index ' + index); 
     } 
    }, 
    items:[{ 
      title: 'Section 1', 
      html: 'test' 
     },{ 
      title: 'Section 2', 
      html: 'test' 
     },{ 
      title: 'Section 3', 
      html: 'test' 
     }] 
}); 
modules_info_panel.getSelectionModel().on('tabselect', function(sm, index, rec){ 
    changeMenuItemInfoArea(menuItemModules, 'you are on tab with index ' + index) 
}); 

附錄

感謝@timdev,這樣的作品,這裏是我如何確定它是標籤(只需通過id,我無法得到該標籤的指數,因爲我可以網格中的行索引):

var modules_info_panel = new Ext.TabPanel({ 
    activeTab: 0, 
    region: 'center', 
    defaults:{autoScroll:true}, 
    items:[{ 
      id: 'section1', 
      title: 'Section 1', 
      html: 'test' 
     },{ 
      id: 'section2', 
      title: 'Section 2', 
      html: 'test' 
     },{ 
      id: 'section3', 
      title: 'Section 3', 
      html: 'test' 
     }] 
}); 

modules_info_panel.items.each(function(tab){ 
    tab.on('activate',function(panel){ 
     changeMenuItemInfoArea(menuItemModules, 'you opened the "' + panel.id + '" tab'); 
    }); 
}); 

replaceComponentContent(regionContent, modules_info_panel); 

hideComponent(regionHelp); 

回答

1

你很近。

當您的tabpanel內的單個面板激活時觸發activate事件。

通過listeners配置密鑰,您可以在配置時將附加處理程序附加到TabPanel中的每個項目。

或者你也可以遍歷所有的標籤粘貼你的聽衆,你走了,是這樣的:

modules_info_panel.items.each(function(tab){ 
    tab.on('activate',function(panel){ ... }); 
} 
1

您還可以使用的TabPanel的「beforetabchange」事件:

tabs.on('beforetabchange', function(tabPanel, newItem, currentItem) { ... }, this); 
相關問題