2

我想在窗口中动态添加一个工具(搜索、帮助、齿轮……),如下所示: http ://www.rahulsingla.com/sites/default/files/content/blog/extjs/extjs-panel -添加工具.htm

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

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

  • 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);

If you ask me "Why not to put this code inside MyWindow.ui.js?", I would answer "because I don't want to put this code manually every time I make changes in the design file (Ext Designer)".

Well, if I open one window, it's seems work ok, but if I open a second at the same time, the tools are duplicated in the second window...

So, any idea how to add tools dynamically in MyWindow.js in this specific case?

4

1 回答 1

3

put 'tools' into initComponent

UIMyWindow = Ext.extend(UIMyWindowUi, {  

initComponent: function() {
  this.tools = [{
               type:'gear',
               handler: function(){
                   // Some code...
               }
    }], 
  UImenuDock.superclass.initComponent.call(this);
于 2011-07-15T13:19:48.683 回答