2011-07-15 41 views
2

我wanto在一個窗口中添加工具(搜索,幫助,齒輪,...)動態,就像這樣: http://www.rahulsingla.com/sites/default/files/content/blog/extjs/extjs-panel-add-tool.htm如何在Ext Js窗口中動態添加工具?

我需要在同一時間創造UIMyWindow的多個實例。

不過,我使用的是分機設計師生成2個文件:

  • MyWindow.ui.js:類聲明。
  • MyWindow.js:方法的實現。

除了Ext Designer在設計時沒有選項工具(我沒有找到)。

我添加工具外MyWindow.js和MyWindow.ui.js,像這樣:

var winMyWindow = new UIMyWindow({ 
    autoShow: 'true', 
    tools: [{ 
       type:'gear', 
       handler: function(){ 
        // Some code... 
       } 
    }] 
}); 

但我想把裏面MyWindow.js此塊。所以,我這樣做:

UIMyWindow = Ext.extend(UIMyWindowUi, { 
    tools: [{ 
       type:'gear', 
       handler: function(){ 
        // Some code... 
       } 
    }], 

initComponent: function() { 
    UImenuDock.superclass.initComponent.call(this); 

如果你問我:「爲什麼不把這個代碼中MyWindow.ui.js?」,我會回答「因爲我不希望每次都手動把這個代碼我在設計文件(Ext Designer)中進行更改「。

好吧,如果我打開一個窗口,它似乎工作正常,但如果我打開在同一時間第二,這些工具在第二個窗口複製...

因此,任何想法如何添加在這種特定情況下在MyWindow.js中動態地使用工具?

回答

3

把 '工具' 成initComponent

UIMyWindow = Ext.extend(UIMyWindowUi, { 

initComponent: function() { 
    this.tools = [{ 
       type:'gear', 
       handler: function(){ 
        // Some code... 
       } 
    }], 
    UImenuDock.superclass.initComponent.call(this); 
+0

完美! 謝謝。 –