PDA

View Full Version : Error when calling this.control



schuc
12 Oct 2012, 4:05 AM
Hi everybody!

I have a strange behaviour in my controller class.
I'm developing with Ext js 4.1.2, MVC - style

I call my controller class in app.js


Ext.application(
{
name: 'ServiceRequest',
appFolder: 'app',
autoCreateViewport: true,
controllers:
[
'CompanyController',
'FacilityController'
]
etc.
});

..and here my Controller class :

Ext.define('ServiceRequest.controller.FacilityController',
{
extend: 'Ext.app.Controller',
refs:[{
ref: 'WestPanel',
selector: 'viewport > westPanelView'
},{
ref: 'LoadCompanyButton',
selector: 'viewport > loadcompanybutton'
}],
config:
{
facilityManager : '',
facilityStore: '',
self: this
},
//call init config
constructor: function(config)
{
this.initConfig(config);

this.setFacilityManager(Ext.create('ServiceRequest.view.FacilityControlManager'));
this.setFacilityStore(Ext.create('ServiceRequest.store.FacilityStore'));

this.callParent();
},

//set handler
init: function()
{
/*
this.control({
//the 'view'
'loadcompanybutton':
{
//the listening event
click: this.onReloadTreeDataClicked
},
//Toolbar click handler in west-panel for button btLoad
'#btLoad':
{
click: this.onToolbarLoadClicked
}
});
*/
}
})

When i run the app without disabling the code in the init call i get an
TypeError: this.application is undefined
Even if i only call the this.control({}) i get the error.
In the same app i created an other controller, where i did similiar the same, it works.

Thanks a lot for any suggestion and help with my problem.

cheers Thomas

vietits
12 Oct 2012, 5:14 AM
When an Ext.app.Application load and create a controller, it will pass a config argument to controller's constructor. This config will have a property named 'application' that points to application instance. Default controller constructor will then copies all the properties of config to controller instance. So, try to fix your code as below:


...
constructor: function(config)
{
this.initConfig(config);


this.setFacilityManager(Ext.create('ServiceRequest.view.FacilityControlManager'));
this.setFacilityStore(Ext.create('ServiceRequest.store.FacilityStore'));


this.callParent(arguments);
},
...

schuc
12 Oct 2012, 5:38 AM
Hi vietits!

Thanks a lot!
Works perfect!
Understanding the ext js goes deeper and deeper :-)