如何在Ext Js窗口中动态添加工具?

时间:2011-07-15 12:45:29

标签: extjs4 extjs extjs3

我想在动态窗口中动态添加工具(搜索,帮助,装备......),如下所示: http://www.rahulsingla.com/sites/default/files/content/blog/extjs/extjs-panel-add-tool.htm

我需要同时创建多个UIMyWindow实例。

但是,我正在使用Ext Designer生成2个文件:

  • MyWindow.ui.js:class declaration。
  • 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中动态添加工具呢?

1 个答案:

答案 0 :(得分:3)

将'tools'放入initComponent

UIMyWindow = Ext.extend(UIMyWindowUi, {  

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