PDA

View Full Version : Controller View 'Getter' Question



jhoweaa
22 Jan 2013, 8:00 AM
I've defined a Controller that I want to be able to use to controller a view and a store. I have no problem with accessing the store, but accessing the view is giving me odd results. My definition looks something like this:



Ext.define('ESGManagerEdu.controller.Issuers', {
extend: 'Ext.app.Controller',


stores: [
'Issuers'
],
views: [
'IssuerList'
],
models: [
'Issuer'
],


init: function() {
this.control({
'search[itemId=companySearch]': {
searchrequested: function(value) {
var store = this.getIssuersStore();
store.clearFilter(true);
store.filter("issuerName", value.value);
},

Ext.define('App.controller.MyView', {

extend: 'Ext.app.Controller',


stores: [
'MyStore'

],
views: [
'MyListView'

],

models: [

'MyModel'

],



init: function() {
this.control({
'search[itemId=foo]': {

someevent: function(value) {

var store = this.getMyStoreStore();

...
// just to test the accessor, not really useful code
var viewHeight = this.getMyListViewView().getHeight(); // blows up

},
...


The line which tries to access the height of the view blows up with the following message:



Uncaught TypeError: Object function constructor(){
// Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
// be sufficient to stop in misbehaving. Known to be required against 10.53, 11.51 and 11.61.
return this.constructor.apply(this, arguments) || null;
} has no method 'getHeight'


What I would have expected is that the 'this.getMyListViewView()' would have returned a constructor for my grid panel (my view extends Ext.grid.Panel). Instead, if I execute the getMyListViewView() method in the debugger (either Chrome or in Firebug) instead of getting a constructor object, I get the text of the constructor method.

This is version 4.1.3 of Ext JS running on Windows 7 in Chrome 24.0.1312.52 m, also Firefox 18.0.

I'm certainly willing to believe that I'm doing something stupid, but perhaps this is a bug?

Thanks.

Jim

skirtle
22 Jan 2013, 4:25 PM
Unlike with stores, calling the getter for a view returns the class, not an instance.

If you read this:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-cfg-views

then this:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-method-getView

you'll find the details are hiding in the docs.

You may want to consider using refs instead if you want a view instance:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-cfg-refs

jhoweaa
23 Jan 2013, 6:16 AM
Ah yes, the explanation is a bit hidden. While I can possibly see the utility of getting the view class, it seems that a controller might also want to talk the view instance. Since the store getter returns the instance of the store, it seems a bit inconsistent that the view getter returns the class.

Thanks for the clarification.

Jim