Without further ado let's dive into ExtJs4 DOM Elements event handling.
Ext.dom.Element is a DOM Element wrapper which encapsulates crossbrowser functionality for DOM manipulation. Although ExtJs is all about its Components (widgets) there might be cases where one would want to handle browser events of DOM Elements (for example constructing your own widget or adding some animations to page). In order to assign event handler to DOM Element one should use
Ext.dom.Element
's addListener method.
Consider that html page contains the following code:
To retrieve<div id="example-node"></div>
Ext.dom.Element
for example-node
one may use Ext.get method:
Since you retrieved correspondingvar exampleElement = Ext.get('example-node');
Ext.dom.Element
you can assign event handler to example-node
using addListener
method. Ext.dom.Element.addListener
takes two parameters: event name and function (actual event handler). Now let's assume that we want to add click
event handler to example-node
(check out Ext.dom.Element
documentation page for full list of available events).
Now let's check docs for
click
event. It's handler may have three parameters:
Knowing all this stuff we can assign handler:click( Ext.EventObject e, HTMLElement t, Object eOpts )
There is also Ext.dom.Element.on method which is shorthand forexampleElement.addListener('click', function(e, t, eOpts){ // handling event here });
addListener
method:
I encourage you to useexampleElement.on('click', function(e, t, eOpts){ // handling event here });
on
rather than addListener
method because of shorter syntax.
No comments:
Post a Comment