[英]ExtJS: Ext.Window Prototypal inherited objects cannot be destroy
[ExtJS 3.4.0] I have a class with prototypal intheritance to Ext.Window
, something like this: [ExtJS 3.4.0]我有一个对
Ext.Window
具有原型原型的类,如下所示:
function Cls_MyWindow() {
.....
var SaveButton = new Ext.Button({...});
var CancelButton= new Ext.Button({...});
.....
Cls_MyWindow.prototype.width = Ext.getBody().getWidth() - 800;
Cls_MyWindow.prototype.height = Ext.getBody().getHeight() - 350;
Cls_MyWindow.prototype.plain = true;
Cls_MyWindow.prototype.buttons = [SaveButton, CancelButton];
.....
}
Cls_MyWindow.prototype = new Ext.Window;
Cls_MyWindow.prototype.constructor = Ext.Window;
When this window is shown, it can be closed by pressing the CancelButton
or the built-in "x" button of Ext.Window
. 当显示此窗口时,可以通过按下
CancelButton
或Ext.Window
的内置“ x”按钮将其Ext.Window
。
When I close it with CancelButton
, SaveButton
and CancelButton
get destroyed normally. 当我用
CancelButton
关闭它时 , SaveButton
和CancelButton
被正常破坏 。 But, if is closed by the "x" button , the buttons cannot be destroyed , the loop is taking forever causing my application to crashed. 但是,如果使用“ x”按钮关闭了按钮 ,则这些按钮将无法销毁 ,因此循环将永远导致我的应用程序崩溃。
After some investigation I found, in ext-all-debug.js , this: 经过一番调查,我在ext-all-debug.js中发现了:
Ext.Panel = Ext.extend(Ext.Container, {
.....
if(Ext.isArray(this.buttons)){
while(this.buttons.length) {
Ext.destroy(this.buttons[0]);
}
}
.....
}
which invoke Ext.destroy
, this: 调用
Ext.destroy
,这是:
Ext.apply(Ext, function(){
.....
destroy : function(){
Ext.each(arguments, function(arg){
if(arg){
if(Ext.isArray(arg)){
this.destroy.apply(this, arg);
}else if(typeof arg.destroy == 'function'){
arg.destroy();
}else if(arg.dom){
arg.remove();
}
}
}, this);
},
.....
}());
What appears to be is that, this.buttons
-from pressing CancelButton- are Ext.Component thus, it get destroyed normally. 似乎是因为
this.buttons
从按CancelButton-是Ext.Component,因此它被正常销毁。 While this.buttons
-from pressing "x"- are not, which leads to the questions . 尽管
this.buttons
按下“ x”按钮,这引发了问题 。
this.buttons
are not the same objects when it is destroy via different way? this.buttons
通过不同方式销毁时不是同一对象? Shedding me some lights is most appreciated. 最好给我洒些灯。 Thank you in advance.
先感谢您。
If we stay within Ext 3.4.0 boundaries, not reaching back to the plain javascript then you haven't done inheritance correctly. 如果我们处于Ext 3.4.0的范围之内,而不是回到普通的javascript,则说明您没有正确完成继承。 Inheritance is already implemented in Ext, so you do not need to go down to prototypes, creating constructors as instances of parent classes, and so on.
继承已经在Ext中实现,因此您无需深入研究原型,将构造函数创建为父类的实例,等等。
Let's suppose you want to define MyWindow
class inheriting from Ext.Window
: 假设您要定义继承自
Ext.Window
MyWindow
类:
Ext.define('MyWindow',{
extend:'Ext.Window'
,method:function(){/* some stuff */}
,closable:false // don't create close box
,closeAction:'hide'
// etc
});
To create an instance: 创建实例:
var win = Ext.create('MyWindow', {
width:800
,height:600
});
win.show();
For more info see Ext.define docs. 有关更多信息,请参见Ext.define docs。
After days, I've found an answered from Inheritance using prototype / “new” . 几天后,我从Inheritance中找到了一个使用prototype /“ new”的答案。 The code around my first code block at the bottom part is where I got it wrong.
我在底部的 第一个代码块中的代码是我弄错的地方。
Cls_MyWindow.prototype = new Ext.Window;
Cls_MyWindow.prototype.constructor = Ext.Window;
The " new " at "new Ext.Window" operator there is my mistake. “ 新 ”的“新Ext.Window”运营商有我的错误。
Answer: Because of the new operator, when I created a new instance of Cls_MyWindow
total of 2 constructors get called: one of the Cls_MyWindow
, another of Ext.Window
. 答:由于使用了new运算符,当我创建一个新的
Cls_MyWindow
实例时,总共调用了2个构造函数:其中一个为Cls_MyWindow
,另一个为Ext.Window
。 Which then cause them to have "their own prototype of buttons " where SaveButton and CancelButton available in Cls_MyWindow
as Ext.Button
objects and in Ext.Window
as a plain Object 然后,它们使它们具有“其自己的按钮原型”,其中SaveButton和CancelButton在
Cls_MyWindow
可用作Ext.Button
对象,而在Ext.Window
可用作普通对象。
Closing Cls_MyWindow with CancelButton -> The buttons can be destroyed in Ext.Window.destroy's way. 用CancelButton关闭Cls_MyWindow->可以用Ext.Window.destroy的方式销毁按钮。 Closing it with "x" -> The buttons cannot be destroyed.
用“ x”关闭它->按钮不能被破坏。
Solution: I change my code to 解决方案:我将代码更改为
//Cls_MyWindow.prototype = new Ext.Window; the old one
Cls_MyWindow.prototype = Ext.Window.prototype;
Cls_MyWindow.prototype.constructor = Ext.Window;
and everything works perfectly 一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.