ExtJS:在组件存在之前将 Ext 事件附加到组件
假设我有一个组件,该组件需要向一个尚不存在但将会存在的组件添加一个事件侦听器。假设这个尚未创建的组件的“beforerender”事件需要这样做。
现在,如果不知道如何在 ExtJS 中执行此操作,我会执行以下操作:
var wait = setInterval(function() {
var cmp = Ext.getCmp('myThing');
if (cmp) {
clearInterval(wait);
cmp.on('beforerender', function() {
// ... do something on render
});
}
}, 20);
How will I do this in Ext?
Let's say I have a component, and this component needs to add an event listener to a component that does NOT exist yet, but will. Let's say it needs to for the 'beforerender' event of this yet-to-be-created component.
As it is right now, without knowing how to do this in ExtJS, I would do something like this:
var wait = setInterval(function() {
var cmp = Ext.getCmp('myThing');
if (cmp) {
clearInterval(wait);
cmp.on('beforerender', function() {
// ... do something on render
});
}
}, 20);
How would I do this in Ext?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
今天早上在一些随机的 github 存储库中找到了答案:
https:// github.com/prettycode/Ext.exts/blob/master/Ext.latentEvent.js
显然,
Ext.ComponentManager
公开了一个onAvailable
事件。创建组件后,它会通过Ext.ComponentManager
进行处理,并且onAvailable
将在添加给定组件后让侦听器知道。Found the answer in some random github repository this morning:
https://github.com/prettycode/Ext.exts/blob/master/Ext.latentEvent.js
Apparently, there's a
onAvailable
event thatExt.ComponentManager
exposes. When a component is created, it makes its way throughExt.ComponentManager
, andonAvailable
will let listeners know after given components have been added.有一个名为“listeners”的配置,它的作用正是如此:
There is a config called "listeners" which does exactly this: