View Full Version : A little confused the difference between controller views & refs

21 Dec 2011, 8:15 AM
Looking at several examples (Twitter, Kiva, etc.) I see this in the controllers:

views : [

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.

21 Dec 2011, 8:21 AM
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).

21 Dec 2011, 9:02 AM
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.