Javascript extjs4.1(rc2)-Ext.panel.panel上的扩展有时无法完成渲染
我有一个扩展到Ext.panel.panel的类 简化代码:Javascript extjs4.1(rc2)-Ext.panel.panel上的扩展有时无法完成渲染,javascript,extjs,rendering,Javascript,Extjs,Rendering,我有一个扩展到Ext.panel.panel的类 简化代码: Ext.define("some.namespace.MyOwnPanel", { extends: "Ext.panel.Panel", constructor: function (config) { var me = this; Ext.apply(this, config); this.callParent(arguments); this
Ext.define("some.namespace.MyOwnPanel", {
extends: "Ext.panel.Panel",
constructor: function (config) {
var me = this;
Ext.apply(this, config);
this.callParent(arguments);
this.layout = "border";
this.centerPanel = Ext.create("Ext.panel.Panel" , {
region: "center",
layout: "fit",
border: false
});
this.westPanel = Ext.create("Ext.panel.Panel", {
region: "west",
layout: "fit",
border: false
});
this.add(this.centerPanel);
this.add(this.westPanel);
this.on("afterrender", function () {
// create grid for center panel. Data is loaded with AJAX in that function and the component is also added to this.centerPanel
me.createGrid();
});
}
}
有时它会工作并触发afterrender事件,但有时它不工作,然后web应用程序崩溃。没有给出错误,但任何ext组件的创建都会在该点之后停止
我试过很多东西。最初的代码主要是由同事编写的,其中包含了更多与4.1兼容的extjs3.1代码。我试着把它改写成合适的4.1代码,但没有成功。我试图将代码移动到initComponent方法,但也失败了
我对如何解决这个问题没有更多的想法。以前有人遇到过这样的事情吗?你做了什么?请告诉我 我认为您需要创建this.centerPanel=Ext.create(“Ext.panel.panel”,{。。。 在initComponent()函数中:
initComponent: function() {
Ext.apply(this, {
centerPanel: Ext.create("Ext.panel.Panel" , { ... },
...
});
this.callParent(arguments);
}
不在构造函数中。此问题与在
构造函数中设置类有关,而不是initComponent
initComponent
是建议的设置类的方法,仅应在特殊情况下重写构造函数。类的设置方式是afterrender
事件如果您的类是使用renderTo
config创建的,则可能不会激发,这将解释有时工作和失败的原因
Ext.define('Bad', {
extend: 'Ext.Component',
constructor: function() {
//the parent constructor is called here and if renderTo
// is defined it will render before the afterrender listener is added
this.callParent(arguments);
this.on('afterrender', function(){
window.alert('rendered')
})
}
})
var works = new Bad();
//this will alert rendered
works.render(document.body)
//this wont
new Bad({renderTo: document.body})
Ext.define('Good', {
extend: 'Ext.Component',
//change constructor to initComponent
initComponent: function() {
this.callParent(arguments);
this.on('afterrender', function(){
window.alert('rendered')
})
}
})
//alerts
new Good({renderTo: document.body})
我最怀疑的一行是Ext.apply(这个,配置);
在它之前添加一个console.log,并确保您传入了正确的输入。它有可能替换这个类实例的属性。我用console.log检查了配置,但它只包含上述类的特定属性;没有覆盖重要的Ext.panel.panel属性。另请参见:you write-extends:“Ext.panel.panel”,不是“extend”。我跟进了你的答案,但不幸的是它没有解决问题。我跟进了你的答案,但不幸的是它没有为我解决问题。@DanielvanDommele没有实际的代码,将很难找出问题。当出现问题时,不会出现“错误”“我通常会检查firebug中所有错误的中断(chrome中的异常暂停)复制错误并调查堆栈跟踪。