Extjs 4.1 (rc2) - Ext.panel.Panel 上的扩展有时无法完成渲染
Extjs 4.1 (rc2) - Extension on Ext.panel.Panel sometimes does not finish 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.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 兼容的 Extjs 3.1 代码的痕迹。我尝试将其重写为正确的 4.1 代码,但没有成功。我试图将代码移动到 initComponent 方法,但也失败了。
我对如何解决这个问题没有更多的想法。以前有没有人遇到过这样的事情,你做了什么?请告诉我!
我认为您需要创建这个.centerPanel = Ext.create("Ext.panel.Panel" , { ...在 initComponent() 函数中:
initComponent: function() {
Ext.apply(this, {
centerPanel: Ext.create("Ext.panel.Panel" , { ... },
...
});
this.callParent(arguments);
}
不在构造函数中。
这个问题与在constructor
中设置的类有关,而不是在initComponent
中设置。 initComponent
是设置类的推荐方法,但构造函数只应在特殊情况下重写。 设置类的方式 如果您的类是使用 renderTo
配置创建的,则可能不会触发 afterrender
事件,该配置将解释有时工作和失败的原因。
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})
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 扩展移相器按钮类不工作
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- TableExport jquery插件:文件名和扩展名问题
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 扩展SVGTextElement时出现Typescript Uncaught TypeError
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- Javascript”;类“;带有参数的扩展
- 试图阻止Chrome通过扩展关闭
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 表达式引擎扩展开发-向呈现的条目添加自定义javascript
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- DataTable按下键选择扩展/导航
- 扩展jQuery插件以更改配置
- Extjs 4.1 (rc2) - Ext.panel.Panel 上的扩展有时无法完成渲染