1. #1
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    557
    Vote Rating
    25
    estesbubba will become famous soon enough estesbubba will become famous soon enough

      0  

    Default A little confused the difference between controller views & refs

    A little confused the difference between controller views & refs


    Looking at several examples (Twitter, Kiva, etc.) I see this in the controllers:

    Code:
    views : [
        'Main'
    ],
    
    
    refs: [{
        ref       : 'main',
        selector  : 'mainview',
        xtype     : 'mainview',
        autoCreate: true
    }]
    From this you automatically get getMainView() and getMain(). I'm confused on what are the best practices for using these and have several questions. We are starting two new projects and using Touch 2.0.

    1. What is the preferred way to create a view in a controller? getMainView().create() or getMain()? Our controller will have several views in the card layout.

    2. Is there a way to have it create the first time and reuse after that? Normally I would do if (!this.view) { this.view = Ext.create()}. With this model it appears you should always use getters instead of setting a property of the instance.

    3. Does the views: [] only define references and not instances?

    It appears that views and refs have some overlapping functionality but still different. Since we are starting two big 2.0 projects now I want to make sure we start out doing things right.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,652
    Vote Rating
    901
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The veiws array does a couple things... It will tell Ext.Loader to load those files. It will also create a getter to get the class so you can create an instance if you want to do it that way.

    The refs uses ComponentQuery to get an instance of a class (and optionally create one if one isn't found).
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    557
    Vote Rating
    25
    estesbubba will become famous soon enough estesbubba will become famous soon enough

      0  

    Default


    Thanks for the quick reply. Your explanation and playing around in the debugger has helped me out. I think our best solution will be to use me.getMainView().create(). We will have some dynamic flows and can use me.getView(name).create(). Then use refs to get the instances and not use autoCreate.

Thread Participants: 1