Extjs sets interceptor _ extjs for an event

Source: Internet
Author: User
Ext. util. Observable has an important function, which allows you to set an interceptor for an event and impose penalties for unified management methods. Use capture () and releaseCapture () to implement this function. Let's first customize an event:

The Code is as follows:


Person = function (name ){
This. name = name;
This. addEvents ("walk ");
}
Ext. extend (person, Ext. util. Observable ,{
Info: function (event ){
Return this. name + 'is + event + 'ing .';
}
});
Var person = new person ('zhang minconn ');
Person. on ('Walk ', function (){
Ext. Msg. alert ('event', person. name +. ');
});


Then we define a button to trigger this walk event:

The Code is as follows:


Var btn = new Ext. Button ({
Id: 'walk ',
Text: 'trigger event click ',
RenderTo: Ext. getBody ()
});
Btn. on ('click', function (){
Person. fireEvent ('Walk ');
});


The event is triggered when the button is clicked, as shown in the following figure:

Now we use the capture () function to intercept event triggering, as shown in the following code:

The Code is as follows:


Var btn2 = new Ext. Button ({
Id: 'cc ',
Text: 'intercept ',
RenderTo: Ext. getBody ()
});
Btn2.on ('click', function (){
Ext. util. Observable. capture (person, function (){
Alert ('fsdjhf ');
Return true;
});
});


Click the btn2 button, and the event will be triggered in the pop-up dialog box .... Now, change the last line of code to return false. How can this problem be solved? The event has been intercepted!

This gives us a chance to choose whether to continue executing the listener function at a certain time or directly abort the event by controlling the return value of the processing function in capture.

We can also set multiple capture () Interception functions for an object. These interception functions form a processing chain. If any of the interception functions returns false, the processing will be aborted.

The releaseCapture () function is a reverse operation of the capture () function. It clears all the interception functions on fireEvent () at one time, but we cannot use it to accurately delete an interception function. Once releaseCapture () is executed, all the previously configured interception functions become invalid.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.