2012-06-14 30 views
1

我有以下看法:ExtJS的視圖創建

Ext.define("FI.view.InstallBaseList", { 
extend: 'Ext.grid.Panel', 
require: 'FI.store.InstallBaseStore', 
title: 'List', 

alias: 'widget.installBaseList', 

icon:'table.png', 

store:'FI.store.InstallBaseStore', 

columns: [], 

divId:'', 
    dockedItems: [], 
height: 200, 
width: 700, 
renderTo: "container", 
enableLocking: true, 
draggable: true, 
resizable: true, 

initComponent: function(config){ 
     console.log("here"); 
    } 
}); 

,這是我嘗試從控制器創建:

list = Ext.widget('installBaseList', params); 

在瀏覽器中我得到這個錯誤:

me.dockedItems.insert is not a function 
addDocked(items=[Object { xtype="header", title="List", titleAlign="left", more...}], pos=0) ext-all-debug.js (line 47051) 
updateHeader(force=undefined) ext-all-debug.js (line 90398) 
beforeRender() ext-all-debug.js (line 90275) 
getRenderTree() ext-all-debug.js (line 26056) 
render(container=Object { dom=div#container, id="container", $cache={...}, more...}, position=undefined) ext-all-debug.js (line 26193) 
constructor(config=Object { divId="container", columns=[0]}) ext-all-debug.js (line 44380) 
callParent(args=[Object { divId="container", columns=[0]}]) ext-all-debug.js (line 3728) 
constructor(config=Object { divId="container", columns=[0]}) ext-all-debug.js (line 56387) 
constructor() ext-all-debug.js (line 3892) 
widget(name="installBaseList", config=Object { divId="container", columns=[0]}) ext-all-debug.js (line 5083) 
(?)() ListCo...5323863 (line 98) 


me.dockedItems.insert(pos + i, item); ext-all-debug.js (line 47051) 

更何況,在initComponent方法中,config似乎是未定義的。爲什麼?

問題在哪裏?

回答

4

initComponent方法必須包含對callParent的調用,以確保父類的initComponent方法也被調用。

這裏是http://jsfiddle.net/nscrob/EcX3Q/11/

你也並不需要發送的參數配置到initComponent,對象的配置已經被分配到組件,可以通過該訪問的修復。所以如果你有: Ext.create('...',{mode:add});在init組件中,你將擁有this.mode = add;

+0

謝謝。你能否也請告訴我爲什麼'config'在initComponent方法中顯示爲undefined? – Dragos

+0

這裏是我說的一個例子,可能你的配置看起來相當http://jsfiddle.net/nscrob/EcX3Q/13/ – nscrob

+0

你先生,是一個救星!你知道一個方法來設置面板的創建列(也許在initComponent中)嗎? – Dragos