I have one function in controller. It will return a value. I have called that function in view using renderer:this.getController('test.controller.Barchart').change(); but it is not working. I am getting an error wind has no method getController(). Can anybody tell me how to call it correctly?
-
1YOU_APP_NAME.app.getController('MyController')Titouan de Bailleul– Titouan de Bailleul2013-04-30 10:45:23 +00:00Commented Apr 30, 2013 at 10:45
Add a comment
|
3 Answers
Having a view call a controller is considered the essence of evil. The view should never be aware of the controller. I'm a lead on a large project that uses ExtJS and we don't allow anything in our views other than the JSON description of the view. The logic that is looking for a controller should likely be in the controller itself.
1 Comment
CrazySabbath
Since I learning/working with ExtJS not that long ago I've a question. How do you handle view listener events without calling controller? Say I have a grid, and I want to execute a controller function on row select event? How do you do that without calling controller from view listener?
please refer below solution!!!
var ControllerRef=<applicationreference>.getController(<ControllerfolderPath>.controllerName);
ControllerRef.<ControllerFunction>();
Example:
var MyApp = Ext.create('Ext.app.Application', {
......
......
});
var ControllerRef = MyApp.getController('general.ManagerController');
ControllerRef.MyFunction();
Thanks
2 Comments
mohan
whether i need to create instance MyApp in view? am getting MYApp is not defined
Eluny
it's not exactly MyApp reference, but reference to View that has this controller set. In my application I call LoginBtn.click of LoginWin with this code:
Ext.ComponentManager.get('LoginWin').getController().onLoginClick(); while MyApp is another window.Try this: You can put your controller as a global variable in your app.js like so:
Ext.define('MySharedData', {
my_Controller:Object
});
In your controller:
MySharedData.my_Controller=this.getController('<ControllerfolderPath>.controllerName');
then call the function that you want, from your view:
MySharedData.my_Controller.my_Function();