Results 1 to 4 of 4

Thread: Can,t access my function!!!

  1. #1
    Sencha User Carlos Souza's Avatar
    Join Date
    May 2015
    Location
    Minas Gerais, Brazil.
    Posts
    29
    Answers
    1

    Default Answered: Can,t access my function!!!

    Hello, Guys!


    I'm relatively new in ExtJS 5 and I'm doing a search plugin for grids. The plugin is almost ready, except for the fact that I am not able to access one of my functions properly through 'triggerfields'. It should be a 'scope' problem, but I don't know it certainly...
    I am posting the code... I think you will better understand my problem if you see my code ...
    When the plugin become ready, I will post it here in the forum


    Thanks in advance.


    Code:
    Ext.define('Ux.gridLiveSearch',{
        extend:'Ext.grid.feature.Feature',
        constructor: function(){
         
              //..some code here  
    
        }, 
        init: function(){
    
    
             //..more code here...
    
            this.test1 = 'Test 1';
            
            this.test2 = 'Test 2';
    
    
            this.textfield = Ext.create('Ext.form.field.Text', {       
                triggers: {
                    
                    search: {
                        
                        cls: 'x-form-search-trigger',
                        handler: this.onTriggerSearch //When called here the function can't access this.test1, this.test2 and this.textfield 
                    },
                    clear: {
                        cls: 'x-form-clear-trigger',
                        handler: this.onTriggerClear //When called here the function can't access this.test1, this.test2 and this.textfield 
                    }
                }
            });
    
    
    
    
            this.button = Ext.create('Ext.button.Button', {       
                text:'Test Button',
                handler: this.onTriggerSearch  //When called here, the same function magically works!!!!                        
    
    
    
    
             });
    
        },
        onTriggerSearch: function(){
    
              alert(this.textfield.getValue() + this.test1 + this.test2); 
    
        },
        onTriggerClear: function(){
    
              alert(this.textfield.getValue() + this.test1 + this.test2); 
        
        }
    
    
    });

  2. Quote Originally Posted by jreusser View Post
    in your init function save the scope:

    Code:
    var me = this;
    then, in the declarations, use that scope again:

    Code:
    triggers: {                                
    search: {                                        
       cls: 'x-form-search-trigger',                    
       scope: me,                    
       handler: function(){ 
          var nowMe = this; 
          console.log(nowMe.this1);
       }               
    }}
    It worked perfectly! Thank you so much!

  3. #2
    Sencha User
    Join Date
    Dec 2013
    Posts
    20
    Answers
    1

    Default

    in your init function save the scope:

    Code:
    var me = this;
    then, in the declarations, use that scope again:

    Code:
    triggers: {                                
    search: {                                        
       cls: 'x-form-search-trigger',                    
       scope: me,                    
       handler: function(){ 
          var nowMe = this; 
          console.log(nowMe.this1);
       }               
    }}

  4. #3
    Sencha User Carlos Souza's Avatar
    Join Date
    May 2015
    Location
    Minas Gerais, Brazil.
    Posts
    29
    Answers
    1

    Default

    Quote Originally Posted by jreusser View Post
    in your init function save the scope:

    Code:
    var me = this;
    then, in the declarations, use that scope again:

    Code:
    triggers: {                                
    search: {                                        
       cls: 'x-form-search-trigger',                    
       scope: me,                    
       handler: function(){ 
          var nowMe = this; 
          console.log(nowMe.this1);
       }               
    }}
    It worked perfectly! Thank you so much!

  5. #4
    Sencha User
    Join Date
    Dec 2013
    Posts
    20
    Answers
    1

    Default

    My pleasure since you said you're new, you might consider reading through some of the guides. I found them immeasurably useful when first starting out.

Similar Threads

  1. How to access function under Application from controllers
    By [email protected] in forum Sencha Architect 2.x: Help & Discussions
    Replies: 0
    Last Post: 4 Sep 2012, 5:40 AM
  2. how to access a function using Ext
    By marc123 in forum Ext: Discussion
    Replies: 2
    Last Post: 25 May 2011, 6:59 AM
  3. Access a function declared on Ext.setup
    By ueilat in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 4 Aug 2010, 4:29 AM
  4. Access function Ext.onReady
    By script in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 27 Aug 2007, 1:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •