admin管理员组文章数量:1389768
I've an observable object defined as follows:
Ext.define ('MyObject', {
mixins: {
observable: 'Ext.util.Observable'
} ,
constructor: function (cfg) {
this.initConfig (cfg);
this.mixins.observable.constructor.call (this, cfg);
...
}
});
Then, I create an instance of this object and attach some listeners:
var obj = Ext.create ('MyObject', {...});
obj.on ({
first: function () {...} ,
second: function () {...} ,
third: function () {...} ,
fourth: function () {...}
});
In the end, I'm gonna destroy the 'obj' instance, but at this point I've to save every listeners previously attached because I'm mad and I need to create another instance of 'MyObject', with the same configuration of 'obj', listeners included.
So, the question is: how can I save every listener of an observable object?
Thank you so much!
I've an observable object defined as follows:
Ext.define ('MyObject', {
mixins: {
observable: 'Ext.util.Observable'
} ,
constructor: function (cfg) {
this.initConfig (cfg);
this.mixins.observable.constructor.call (this, cfg);
...
}
});
Then, I create an instance of this object and attach some listeners:
var obj = Ext.create ('MyObject', {...});
obj.on ({
first: function () {...} ,
second: function () {...} ,
third: function () {...} ,
fourth: function () {...}
});
In the end, I'm gonna destroy the 'obj' instance, but at this point I've to save every listeners previously attached because I'm mad and I need to create another instance of 'MyObject', with the same configuration of 'obj', listeners included.
So, the question is: how can I save every listener of an observable object?
Thank you so much!
Share Improve this question asked Apr 25, 2013 at 21:45 WilkWilk 8,14310 gold badges47 silver badges71 bronze badges 2- Why not describe the listeners in the constructor || initComponent of an object? Or I do not understand the question? – Vlad Commented Apr 25, 2013 at 22:27
- Because I don't know which listeners are going to get attached on that object. – Wilk Commented Apr 25, 2013 at 22:34
1 Answer
Reset to default 6You can try create a getListeners() method for your object:
Ext.define ('MyObject', {
...
getListeners: function() {
var me = this,
l = {};
for(var event in me.hasListeners) {
Ext.each(me.events[event].listeners, function(listener) {
l[event] = listener.o[event];
});
}
return l;
}
});
...
var listeners = obj.getListeners();
obj.destroy();
obj2.on(listeners);
See on jsfiddle: http://jsfiddle/8GMsp/
Note: I have not tried to use it in a real application. May be require revision.
本文标签: javascriptExtJS 4 get every listeners of an observable objectStack Overflow
版权声明:本文标题:javascript - ExtJS 4 get every listeners of an observable object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744730117a2621997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论