Results 1 to 3 of 3

Thread: A little confused the difference between controller views & refs

  1. #1
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    628
    Vote Rating
    40
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    628
    Vote Rating
    40
      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.

Posting Permissions

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