-
21 Dec 2011 8:15 AM #1
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:
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.Code:views : [ 'Main' ], refs: [{ ref : 'main', selector : 'mainview', xtype : 'mainview', autoCreate: true }]
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.
-
21 Dec 2011 8:21 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,581
- Vote Rating
- 433
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Dec 2011 9:02 AM #3
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.


Reply With Quote