2012-10-03 53 views
3

我正在使用Ext JS 4.1.1爲網頁創建一個GUI。我試圖創建一個組件('GeneSearchComponent'),我可以在更復雜的佈局中使用它。但由於某種原因,我無法將'GeneSearchComponent'的實例插入hpanel。我在擴展預定義的'Ext.panel.Panel'類(以及創建我自己的「小部件」)時缺少什麼?正確的方式來擴展Ext.panel.Panel?

如果我刪除對「Ext.create('gene-search-component', ...」的呼叫,則一切正常;如果我把它放回去,一切都會中斷。我想知道爲什麼。

(我還沒有包括「基因組合框」。我非常確信,這不是我的問題的根本原因。)的定義

感謝您的時間!

圖奧馬斯

Ext.define('GeneSearchComponent', { 
    extend: 'Ext.panel.Panel', 
    alias: ['gene-search-component'], 
    constructor: function(cnfg) { 
     this.callParent(arguments); 
     this.initConfig(cnfg); 
    }, 
    config: { 
     collapsible: true, 
     frame: true, 
     title: 'Search', 
     bodyPadding: '15 15 15 15', 
     width: 350, 
     layout: { 
      type: 'vbox', 
      align: 'left' 
     }, 
     items: [ 
      Ext.widget('gene-combobox', { 
       id: 'comboboxid' 
      }), 
      Ext.create('Ext.Button', { 
       text: 'Search', 
       handler: function() { 
        dosomething(); 
     }})] 
    }, 
    onRender: function() { 
     this.callParent(arguments); 
    } 
}); 

Ext.application({ 
    name: 'FW', 
    launch: function() { 
     var bd = Ext.getBody(); 
     var div = Ext.get("search_form"); 

     var hpanel = Ext.create('Ext.panel.Panel', { 
      id: 'horizontal-panel', 
      title: "HBoxLayout Panel", 
      layout: { 
       type: 'hbox', 
       align: 'middle' 
      }, 
      items: [ 
       Ext.create('Ext.container.Container', { 
        id: 'another-panel', 
        title: "VBoxLayout Panel", 
        width: 250, 
        layout: { 
         type: 'vbox', 
         align: 'left' 
        }, 
        items: [{ 
         xtype: 'panel', 
         width: 250, 
         title: ' Panel One', 
         flex: 2 
        },{ 
         xtype: 'panel', 
         width: 250, 
         title: ' Panel Two', 
         flex: 1 
        },{ 
         xtype: 'panel', 
         width: 250, 
         title: ' Panel Three', 
         flex: 1 
       }]}), 
       Ext.create('gene-search-component', { 
        id: 'searchPanel', 
      })], 
      renderTo: div, 
     }); 
    } 
}); 
+0

你爲什麼定義'GeneSearchComponent'定製'constructor'?另外,爲什麼在使用'xtype'時爲什麼使用'Ext.widget'和'Ext.create'?雖然不確定,但這些可能是你問題的根源。 – Izhaki

+0

lzhaki,如果我刪除構造函數,JavaScript引擎不再抱怨「Uncaught TypeError:Object# has no method'setOwner'。」但是,將它保留下來會影響組件的呈現方式。就xtype,Ext.widget和Ext.create而言,我認爲它們或多或少相互等價。 – tuope

+0

你能詳細說明一下將構造函數退出的效果嗎?另外,使用'xtype'是否使用'Ext.create'或'lazy Instantiation'可能很重要,但其背後的解釋很複雜,我建議你先閱讀[this](http://skirtlesden.com/文章/配置對象 - 上的原型)。 – Izhaki

回答

1

的問題是,配置其別名的時候你有沒有考慮到gene-search-componentwidget命名空間。

alias: 'widget.gene-search-component' 

也附和你的OP你做了很多不必要的打字建立在你的方式組成部分的意見。你應該使用xtype字段而不是在任何地方使用Ext.Create。我修改了你的代碼,告訴你它可能更簡單。

http://jsfiddle.net/hzXx8/

+1

非常感謝!我能夠得到它的工作。我很欣賞你的代碼的簡單性。 lzhaki和傑米,感謝您花時間與此。希望有一天我可以償還這個好處。 – tuope

相關問題