update:
新代码:
Ext.define('Fiddle.MyCmp',{
extend:'Ext.Component'
,alias:'widget.mycmp'
,config:{
html:'MyCmp'
}
,initialize:function() {
var me = this;
console.log(me);
Ext.Function.defer(me.destroy, 5000, me);
Ext.Function.defer(function(){
console.log('after 8 seconds');
console.log(this);
}, 8000, me);
}
});
Ext.application({
name : 'Fiddle',
ref:{
cmp: 'mycmp'
},
launch : function() {
Ext.Viewport.add({
xtype:'mycmp'
});
}
});
8秒后,我仍然可以打印出该组件。这是控制台日志:
类{onInitializedListeners:数组[0],initialConfig:对象,id:
“ext-mycmp-1”,getUniqueId:函数,getId:函数…} VM1639:39
8 秒后 VM1639:43 类 {onInitializedListeners: Array[0],
初始配置:对象,id:“ext-mycmp-1”,getUniqueId:函数,
getId:函数...}
我正在尝试在自定义组件中添加自毁功能。
但这根本行不通。
这是我的代码:
Ext.define('NoiseComponent', {
extend: 'Ext.Component',
xtype: 'noisestation',
config: {
name: null,
updatedTime: new Date(),
listeners: {
destroy: function() {
console.log("do something before destroy()");
//thisComponent.destroy();
},
updatedata: function(thisComponent, newData, eOpts) {
var startTime = newData[0].get("NoiseTime");
this.config.updatedTime = new Date();
},
initialize: function(thisComponent, eOpts) {
console.log("initialize component");
setTimeout(function() {
thisComponent.selfDestory(thisComponent);
}, 5000);
}
}
},
drawNoise: function() {
console.log("drawNoise");
},
selfDestory: function(thisComponent) {
console.log("self-destroy");
thisComponent.destroy(thisComponent);
}
});
var c = Ext.create("NoiseComponent");
console.log(c);
c.destroy();
//c.fireEvent('destroy');
console.log("after destroyed");
console.log(c);
setTimeout(function() {
console.log("after 5s");
console.log(c);
}, 5000);
这是我得到的控制台日志:
初始化组件 VM1591:44 类 {onInitializedListeners:
Array[0],initialConfig:对象,id:“ext-noisestation-1”,
getUniqueId:函数,getId:函数…} VM1591:72 做一些事情
在 destroy() VM1591:65 被销毁之后 VM1591:77 类
{onInitializedListeners:数组[0],initialConfig:对象,id:
“ext-noisestation-1”,getUniqueId:函数,getId:函数…}
VM1591:78 自毁 VM1591:60 在 destroy() 之前做一些事情
5 秒后 VM1591:65 VM1591:81 类 {onInitializedListeners: Array[0],
初始配置:对象,id:“ext-noisestation-1”,getUniqueId:
函数,getId:函数...} VM1591:82
这是我的 sencha jsfiddlehttps://fiddle.sencha.com/#fiddle/6cl https://fiddle.sencha.com/#fiddle/6cl