Extjs 修改initComponent()中的项
我在Extjs 修改initComponent()中的项,extjs,extjs4.1,Extjs,Extjs4.1,我在initComponent()中创建了一些项 问题是,this.items以某种方式引用了类变量,而不是实例变量 因此,当我创建两个实例时,我会得到两个按钮 items: [], initComponent: function() { this.items.push( { xtype: 'button', ... }) ; this.callParent( arguments ); } 因为我必须使用push,每次新元素被推入时 是否存在与此类似的实例。在创建按钮之前,我可以在其中
initComponent()中创建了一些项
问题是,this.items
以某种方式引用了类变量,而不是实例变量
因此,当我创建两个实例时,我会得到两个按钮
items: [],
initComponent: function() {
this.items.push( { xtype: 'button', ... }) ;
this.callParent( arguments );
}
因为我必须使用push,每次新元素被推入时
是否存在与此类似的实例。在创建按钮之前,我可以在其中修改定义,还是必须手动检查重复项?您可以重载构造函数并调整其中的配置:
constructor: function(config)
{
config.items.someButton = { xtype: 'button', ... };
this.callParent([config]);
}
您不应该返回this.callParent(参数)代码>
这就足够了:
initComponent: function() {
var me = this;
me.items = { xtype: 'button', ... }; //Are you sure items is filled up here?
me.callParent();
}
此外,如果您正在编写自己的“组件”,并且希望在Ext.create
中传递参数,我始终会执行以下操作:
constructor: function (config) {
var me = this;
Ext.apply(me, config);
me.callParent();
}
这将用您在Ext.create()
arrr中提交的条目声明覆盖类中的条目声明。可能Ext.menu.menu
希望项目是一个数组。如果使用对象,则不会创建项目。如果我使用数组并将项推入,它们就会被创建,但每次调用initComponent时,就会有更多的项被推入,这就是为什么我首先会遇到这个问题:(虽然我的questioninitComponent中编辑的代码只被调用一次,但项可以是数组或1个对象(之后会转换为数组)谢谢。我找这个已经很久了。