PDA

View Full Version : Generated View Getters



ttbgwt
5 Apr 2012, 6:31 PM
Ext.define (http://docs.sencha.com/ext-js/4-0/#!/api/Ext-method-define)('MyApp.controller.Posts',{
extend:'Ext.app.Controller (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.app.Controller)',
views:['posts.List','posts.Edit'],
//the rest of the Controller here});

In the code above, what is the automatic getter that is created? Is is getPostsListView()?

vietits
5 Apr 2012, 6:36 PM
Yes, that's right.

ttbgwt
5 Apr 2012, 6:49 PM
It didnt work for me, not sure if something is going on because of lowercase posts.List

vietits
5 Apr 2012, 7:09 PM
Ext.define('MyApp.controller.Posts',{
extend:'Ext.app.Controller',
views:['posts.List','posts.Edit'],
...
init: function(){
var me = this;
...
me.callParent(arguments);
console.log('Posts controller init', me);
}
...

Let try by adding the above red line of code, run and watch the console log. Do you see getPostsListView method?

ttbgwt
7 Apr 2012, 8:32 AM
The generated getter is there but it is empty.

vietits
7 Apr 2012, 4:14 PM
View & Model getters just return respective classes, not instances as Store getters do.

vadimv
8 Apr 2012, 2:44 AM
To get views instances use refs.


refs:[{
ref: 'postsListView', // the name you want for getter
selector: 'postslistview' //views alias/xtype
}]

ttbgwt
9 Apr 2012, 8:41 AM
I had the refs working fine, but whats the point of an auto generated getter for views if they don't return instances?

vadimv
9 Apr 2012, 9:57 AM
First that comes in my mind is that you could have more views of the same type in a controller, so that's why better to manage them with selectors. Regarding views class getter, this could be useful in controller.