1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    35
    Vote Rating
    1
    Oxii is on a distinguished road

      0  

    Default Check Change Listener

    Check Change Listener


    What is the right way to handle menu check items events ?
    I have this menu:
    Code:
     {      xtype: 'button',  
            id: 'types_btn',  
           autoWidth: true,   
           text: 'Types',  
           menu: {        
               xtype: 'menu',   
               frame: true,        
              id: 'types_menue',     
              items: [              
             {                    
                  xtype: 'menucheckitem',           
                  id: 'f_type',                 
                  text: 'first',                  
                  listeners: {                    
                     checkchange: {                 
                         fn: me.onFirstButtoncheckchange,           
                        scope: me           
                             }                          
                }                  
         },                      
     {                   
                     xtype: 'menucheckitem',     
                      id: 's_type',           
                     text: 'second',                  
                     listeners: {                        
                           checkchange: {                 
                                  fn: me.onSecondButtoncheckchange,         
                                 scope: me                              
          }                      
                    }             
              }


    Then the functions:

    Code:
    onFirstButtoncheckchange: function(menucheckitem, checked, options) {   
     var t = Ext.getCmp('f_type');        
           if (t.checked)              
         goToFunction(???);            
            .        
            .    
    }, 
    
    onSecondButtoncheckchange: function(menucheckitem, checked, options) {    
    var t = Ext.getCmp('s_type');       
            if (t.checked)             
          goToFunction(???);        
             .          
            .    },


    1- Is there anyway to use one listener and gather all different functions in it ?

    2- How can I send the current item to goToFunction() as you see in the code ?

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,592
    Vote Rating
    323
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      1  

    Default


    The first argument passed to the listener function is the CheckItem instance. You don't need to look it up using Ext.getCmp, you already have it.

    In general you should avoid using fixed ids and Ext.getCmp.

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    35
    Vote Rating
    1
    Oxii is on a distinguished road

      0  

    Default


    Thank you.

Thread Participants: 1

Tags for this Thread