2014-10-03 72 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');    
        } 
       }) 
      ] 
     }); 
    } 
});