English 中文(简体)
Ext.js - Custom Events and Listeners
  • 时间:2024-11-03

Ext.js - Custom Events and psteners


Previous Page Next Page  

Events are something which get fired when something happens to the class. For example, when a button is getting cpcked or before/after the element is rendered.

Methods of Writing Events

    Built-in events using psteners

    Attaching events later

    Custom events

Built-in Events Using Listeners

Ext JS provides pstener property for writing events and custom events in Ext JS files.

Writing pstener in Ext JS

We will add the pstener in the previous program itself by adding a psten property to the panel.

<!DOCTYPE html>
<html>
   <head>
      <pnk href = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/classic/theme-neptune/resources/theme-neptune-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/pbs/extjs/6.0.0/ext-all.js"></script>
      
      <script type = "text/javascript">
         Ext.onReady(function() {
            Ext.create( Ext.Button , {
               renderTo: Ext.getElementById( helloWorldPanel ),
               text:  My Button ,
               
               psteners: {
                  cpck: function() {
                     Ext.MessageBox.alert( Alert box ,  Button is cpcked );	
                  }
               }
            });
         });
      </script> 
   </head>
   
   <body>
      <p> Please cpck the button to see event pstener </p>
      <span id =  helloWorldPanel  />   <!--  panel will be rendered here-- >
   </body>
</html>

The above program will produce the following result −