2012-12-30 14 views
0

我嘗試添加this.callParent(參數)的標籤面板的initialize事件 通過http://www.sencha.com/forum/showthread.php?234909-tab-panel-doesn-t-switch-between-tabs-when-added-dynamically的建議,但我得到:Tab平板的行爲符動態

Uncaught Error: this.callParent() was called but there's no such method (doFire) found in the parent class (Ext.Base). 

有人能指出我在正確的方向?

謝謝。

我的控制器如下:

Ext.define('MyApp.controller.MyController', { 
    extend: 'Ext.app.Controller', 

    config: { 
     refs: { 
      mytabpanel: '#mytabpanel' 
     } 
    }, 

    init: function(application) { 

     this.control({ 
      mytabpanel: { 
       initialize: function(component, options){ 
        var bar = component.getTabBar(); 

        bar.insert(0, { flex:1, xtype:'toolbar', title: '' }); 

        bar.insert(bar.getItems().length, 
        { 
         xtype: 'toolbar', 
         flex: 1, 
         title: '', 
         items: [ 
         { 
          xtype : 'button', 
          docked: 'right', 
          ui: 'round', 
          iconCls: 'info', 
          iconMask: true, 
          handler: function(){      
          } 
         } 
         ] 
        }); 
        this.callParent(arguments); 
       } 
      } 
     }); 
    } 
}); 

我的看法如下:

Ext.define('MyApp.view.MyTabPanel', { 
    extend: 'Ext.tab.Panel', 

    config: { 
     id: 'mytabpanel', 
     items: [ 
      { 
       xtype: 'container', 
       title: 'Tab 1', 
       iconCls: 'info', 
       html: 'tab 1' 
      }, 
      { 
       xtype: 'container', 
       title: 'Tab 2', 
       iconCls: 'info', 
       html: 'tab 2' 
      }, 
      { 
       xtype: 'container', 
       title: 'Tab 3', 
       iconCls: 'info', 
       html: 'tab 3' 
      } 
     ], 
     tabBar: { 
      docked: 'bottom' 
     } 
    } 
}); 

編輯週日,12月30日上午06點57(GMT - 4:00)

從搜索網絡我現在認爲,因爲我重寫初始化然後我需要調用超類的初始化方法,以便其代碼也將被執行。正如user1479606所指出的,調用this.callParent將永遠不會工作。所以,問題變成:我如何調用超類的初始化方法?

回答

0

我覺得你的應用程序不會在你的情況下工作,因爲你應該在你的觀點不是你的控制器使用this.callParent(arguments)否則你的父類永遠是Ext.Base

爲了更容易理解和更好的方法,你爲什麼不跟着煎茶觸摸2約定是這樣的:

config: { 
    refs: { 
     mytabpanel: '#mytabpanel' 
    } 

    control: { 
     mytabpanel: { 
      initialize: 'domytabpanel' 
     } 
    } 
}, 

domytabpanel: function(component, options) { 
    var bar = component.getTabBar(); 

    bar.insert(0, { 
     flex:1, 
     xtype:'toolbar', 
     title: '' 
    }); 

    bar.insert(bar.getItems().length, 
    { 
     xtype: 'toolbar', 
     flex: 1, 
     title: '', 
     items: [ 
     { 
      xtype : 'button', 
      docked: 'right', 
      ui: 'round', 
      iconCls: 'info', 
      iconMask: true, 
      handler: function(){      
      } 
     } 
     ] 
    }); 
} 

希望它能幫助:)

+0

謝謝你的答案。我嘗試了你的方法,並且,雖然它更容易理解,但它還會在動態添加按鈕和工具欄之後出現標籤欄已損壞的問題。當我插入後點擊一個標籤,我得到「Uncaught TypeError:Object [object Object]沒有方法'setActive'」,並且標籤欄中所有三個選項卡的行爲都被破壞。這是我打算通過調用callParent解決的問題。 –

+0

由於你的tabbar已經有3個條目'bar.insert(3,{....}),所以將插入索引更改爲三個' – Eli