1. #1
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    metalinspired is on a distinguished road

      0  

    Default Help with using refs in control function

    Help with using refs in control function


    Hi,

    Now I know this has been asked before and I read all the posts I could find but I still can't get it to work.
    An example of my controller would be:
    PHP Code:
    Ext.define('myApp.controller.Operator', {
        extend
    'Ext.app.Controller',
        .......
            
    init: function() {
            
    this.control({
                
    '#operatorList > #container' : {
                    
    render: function(component) {
                        if (!
    component.isHidden()) {
                            
    // do something
                            
    } else {
                            
    // do something else
                            
    }
                        }
                    },
                },
            });
        },
        
    refs: [{
            
    ref'container',
            
    selector'#operatorList > #container',
        },],
        ....
    }); 
    this functions fine but I'm writing same selector twice and if I do this nothing happens
    PHP Code:
    Ext.define('myApp.controller.Operator', {
    ​    extend'Ext.app.Controller',
        .......
            
    init: function() {
            
    this.control({
                
    ​container: {
                    
    render: function(component) {
                        if (!
    component.isHidden()) {
                            
    // do something
                            
    } else {
                            
    // do something else
                            
    }
                        }
                    },
                },
            });
        },
        
    refs: [{
            
    ref'container',
            
    selector'#operatorList > #container',
        },],
        ....
    }); 
    I tried a bunch of other approaches like moving all to config property and all code snippets I could find in other posts but I'm still stuck

  2. #2
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    654
    Vote Rating
    26
    vadimv will become famous soon enough vadimv will become famous soon enough

      0  

    Default


    try your selectors in console with Ext.Component.query() and see if returns any results.

  3. #3
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    metalinspired is on a distinguished road

      0  

    Default


    Code:
    They are working as excepted.
    I use getter methods to access view components throughout the controller without any problem.
    Ignore my reply it seems I do have some sort of mistake

  4. #4
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    metalinspired is on a distinguished road

      0  

    Default


    Corrected the error but it didn't have any effect.
    Even with error the selector would return valid component as long as only one view was shown.

  5. #5
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    654
    Vote Rating
    26
    vadimv will become famous soon enough vadimv will become famous soon enough

      0  

    Default


    Quote Originally Posted by metalinspired View Post
    Even with error the selector would return valid component as long as only one view was shown.
    If you mean that you get results trough CQ when is shown or hidden, then yes, that's how should be. CQ returns a result only if the queried component is instantiated/created, if not then returns nothing.

  6. #6
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    metalinspired is on a distinguished road

      0  

    Default


    Hmmmm
    Judging from your comment it seems I misunderstood use of refs in control function.
    Controllers are loaded before, most of, views are created so if I try to use a ref inside control function to add listener to certain component it won't function since that component doesn't exist yet?
    If that is true how come that when I use same selector in control function it works even when view is not created yet?

Thread Participants: 1

Tags for this Thread