PDA

View Full Version : Getting controller reference when function is called outside of controller scope



hermann.s
19 Feb 2014, 10:02 AM
Hi,

I have an array of function of a controller, that is outside the scope of the controller.
When I console.log(this) from within the function, I get the function scope.

So I thought I should get a reference to the controller and continue my work from there.
I ended up with this function :


clearSearch: function () {
var me = MCS.Application.getController('MCS.controller.Search');
me.getSearchResultStore().removeAll();
me.getSearchCaseStore().removeAll();
},

However, I get the following error :

Uncaught TypeError: Object [object Object] has no method 'doInit'
which comes from Ext.app.Application.

Anyone know how to solve this?

palakurthivishal
19 Feb 2014, 10:37 PM
Hello hermann.s,
Please note that to get application instance you need to call a method named " getApplication" of your application. Like this,
MCS.getApplication().getController('MCS.controller.Search')

hermann.s
20 Feb 2014, 4:35 AM
This is not the problem. My application instance is under MCS.Application.

The problem comes with passing a function as a parameter to a method outside the controller, then trying to execute this function outside of the controller.
Trying to get the controller using the getController method then fails.

However, if I invoke the method from within the control, for example using an event, it works fine.

swati.singhal
6 Nov 2015, 9:05 AM
Did you get to solve this? I am facing exactly the same error. I have a veiw controller. All pages have an included panel of buttons common across all pages for navigating back and next.

I need to call a method in the controller when the user clicks on any of the common buttons. The myapp.app.getController("<controller_name>").<methodName>() gives me a doInit method not defined.

Any clue?