聲明:我對ExtJS(版本5.01)相對較新。我希望能找到一些ExtJS專家來指出我的正確方向: 我在指定initComponent
方法內和items
配置時出現錯誤。下面的代碼生成錯誤:EXTJS項目配置中的內聯initComponent方法
「遺漏的類型錯誤:無法讀取的未定義的屬性‘項目’」
當北子面板的「initComponent」功能被註釋掉錯誤消失。我有這種感覺,我錯過了初始化順序。
Q:我如何可以指定一個子項內的items
配置的initComponent
方法?
Ext.define('MyApp.view.TestView', {
extend: 'Ext.panel.Panel',
title: 'Parent',
height: 300,
layout: 'border',
items: [{
xtype: 'panel',
region: 'north',
title: 'North Child',
/* Problematic function: If commented, it works */
initComponent: function(){
console.log("test north child");
this.callParent(arguments);
}
}],
initComponent: function(){
console.log("Test parent");
this.callParent(arguments);
}
});
你不能這樣做!看看[這個問題](http://stackoverflow.com/questions/14254321/best-practice-for-overriding-classes-properties-in-extjs/14254627#14254627)關於重寫的進一步信息。你的問題是,函數的範圍將是'MyApp.view.TestView'實例的範圍。 – sra 2014-09-02 05:58:04
是否有一種ExtJS方法將上下文(即從配置生成的對象)附加到函數中?東西沿一個函數包裝與範圍配置的線? – user1362700 2014-09-02 06:17:57
請告訴我們爲什麼您要在子項上使用initComponent函數。大多數時候,這是沒有必要的。 – Alexander 2014-09-02 07:16:11