Reputation: 5802
BackGround: I am loading a sencha mobile site in the webview of the Android device and accessing a function declared inside sencha controller from the java class as below.
webView.loadUrl("javascript:getMeNumbers();");
This function is declared inside my controller
getMeNumbers : function(value) {
console.log('Controller: Function called >> getMeNumbers');
}
Issue : I am able to call this controller function from java class when I am running this application in development mode. But as soon as I create production build and try to call this controller function from java class, it starts giving me the error:
'ReferenceError: Can't find variable: getMeNumbers at undefined:1''` in the console.
Any ideas why is it not working in the production version but works only in the development version? Any ideas or pointers would help a lot.
Thanks
Upvotes: 1
Views: 1259
Reputation: 5087
The controller functions are not global functions, so you can't call them directly.
Assuming that your application name is APP, and your controller is "MainController", you can try this:
webView.loadUrl("javascript:APP.app.getControllerInstances()['APP.controller.MainController'].getMeNumbers()");
An alternative way is to use routes: In your controller, add a routes config:
routes:{
'getmenumbers': 'getMeNumbers'
}
and then:
webView.loadUrl("#getmenumbers");
Upvotes: 1
Reputation: 7055
When the app is build that is js/css are compressed, it renames function,variables names to shorten ones. It usually, removes functions that compressor thinks not useful. This is usually done to reduce size of files.
So in your case too, compressor might have renamed function to something else or least probably removed if it's not being called from any of js files.
What you can do is identify the function name after compressing js files. Try searching for function body.
Upvotes: 1