2014-10-03 73 views
0

我有這個要求來改變按鈕點擊面板(卡布局)內的活動項目。該按鈕存在於另一個不同的面板中。我嘗試了下面,但它不工作。點擊按鈕後面板不會改變。如何更改按鈕點擊卡內佈局的面板 - extjs 4

Ext.getCmp('PanelID')。layout.setActiveItem('requiredcardID'); - 我在按鈕處理程序中使用此代碼。

是setActiveItem不正確的方法還是我在錯誤的上下文中使用它?

回答

1

這看起來像正確的語法 - 可能檢查您的ID以確保您獲得對組件的引用?此撥弄用5,但我4測試,以及:

https://fiddle.sencha.com/fiddle/ba6/

Ext.application({ 
    name : 'Fiddle', 

    launch : function() { 
     var panel = Ext.create('Ext.Panel',{ 
      renderTo:Ext.getBody(), 
      title:'myPanel', 
      items: [ 
       Ext.create('Ext.panel.Panel', { 
        layout: 'card', 
        id: 'PanelID', 
        activeItem: 0, 
        items: [Ext.create('Ext.panel.Panel', { 
         itemId: 'card-1', 
         html: 'hello' 
         }), 
         Ext.create('Ext.panel.Panel', { 
          itemId: 'card-2', 
          html: 'hello2' 
         })] 
       }), 
       Ext.create('Ext.Button', { 
        text: 'change item in layout', 
        handler: function() { 
         Ext.getCmp('PanelID').layout.setActiveItem('card-2');    
        } 
       }) 
      ] 
     }); 
    } 
});