ExtJS 新手。我有以下代码。
var comp;
console.log('comp is - ' + comp);
comp = Ext.create('Ext.Component', {
listeners : {
beforedestroy : function(comp) {
console.log('beforedestroy .. ');
},
destroy : function(comp) {
console.log('destroy .. ');
}
}
});
console.log('comp is - ' + comp);
console.log('comp id is - ' + comp.getId());
comp.destroy();
console.log('comp is - ' + comp);
console.log('comp id is - ' + comp.getId());
Run Code Online (Sandbox Code Playgroud)
chrome 的控制台输出是
comp is - undefined
comp is - [object Object]
comp id is - component-1009
beforedestroy ..
destroy ..
comp is - [object Object]
comp id is - component-1009
Run Code Online (Sandbox Code Playgroud)
看起来即使在组件被销毁之后,变量仍然保留对原始组件的引用。我期望变量在销毁后具有未定义或 null 的值。这是正常行为吗?
Ext-JS 不可能取消对现有组件的引用,因为 JavaScript 没有类似 C++ 的引用。
例如:
var a = {b:2};
var b = a;
// a and b both reference `{b:2}`, there is nothing you can do
// to `{b:2}` that would change a or b to be null
Run Code Online (Sandbox Code Playgroud)
您可以使用未记录的属性检查组件是否已被销毁isDestroyed
。
comp.isDestroyed // true
Run Code Online (Sandbox Code Playgroud)
您还会注意到该组件已从注册表中删除
Ext.getCmp(comp.id); // undefined
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
851 次 |
最近记录: |