Results 1 to 3 of 3

Thread: Variables accessible from all controller functions? (MVC)

  1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    91
    Answers
    6
    Vote Rating
    0
      0  

    Default Variables accessible from all controller functions? (MVC)

    Hey all,

    I'm using the MVC application structure. I've got a controller with quite a few functions in it. They all access a lot of the same components in my application but I think I've written it very inefficiently.

    For example, I have several buttons that affect the grid in my application. In each button function I have to do something like
    Code:
    var panel = button.up(panel);
    var grid = panel.down(grid);
    Instead of having those two lines in each button function, is there somewhere in the controller where I can define panel and grid (and the other components in my application) so they can be accessed by all my controller functions?

    thank you!

  2. #2
    Sencha User crysfel's Avatar
    Join Date
    Feb 2008
    Location
    New York, USA
    Posts
    218
    Answers
    7
    Vote Rating
    9
      1  

    Default

    You can try the references:

    Code:
    Ext.define('YourApp.controller.Main',{
        extend : 'Ext.app.Controller',
    
        refs : [
            {ref:'grid',selector:'acontainer anotherpanel grid[itemId=yourId]'}
        ],
    
        aFunction : function(){
            this.getGrid().getStore().load();
        }
    });
    First you define a reference with a selector, then you can access that reference by a dynamic method called "getYourReferenceName".

    These references are accesible only by the current controller.

    Regards

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    91
    Answers
    6
    Vote Rating
    0
      0  

    Default

    Thank you, I've done some more reading about references now.

    So you can refer to specific instances of views in your app right? And once defined, calling a reference should be faster than doing a component query?

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
  •