【发布时间】:2014-09-02 04:40:05
【问题描述】:
免责声明:我对 ExtJS(5.01 版)比较陌生。我希望能联系到一些 ExtJS 专家来为我指明正确的方向:
在指定initComponent 方法within 和items 配置时出现错误。下面的代码会产生错误:
"Uncaught TypeError: Cannot read property 'items' of undefined"
当北子面板的'initComponent'函数被注释掉时,错误消失。我觉得我错过了初始化顺序的一些东西。
问:如何在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);
}
});
【问题讨论】:
-
你不能这样做!看看this question 更多关于覆盖的信息。您的问题是,函数的范围将是“MyApp.view.TestView”实例的范围。
-
是否有 ExtJS 方法将上下文(即从配置生成的对象)附加到函数?类似于带有作用域配置的函数包装器?
-
请告诉我们您为什么要在孩子上使用 initComponent 函数。大多数时候,没有必要。
标签: javascript extjs components