6

How can I call function which is inside controller from out side controller function like might be phone gap call back function

Here is the function defined out side the controller

  function onDeviceReady() {
    //do ALL your localstorage stuff here
    console.log('In onDeviceReady() function');
    somefunction();// this is not working
  }

Here is the controller class

     Ext.define('FCELB.controller.LoginController', {
        extend: 'Ext.app.Controller',
        config: {
            refs: {
                username: '#username',
                password: '#password'
            },

            }

        },      

        init: function () {
            console.log('Login controller');
            document.addEventListener("deviceready", onDeviceReady, false);
            //onDeviceReady();
        },

        somefunction:function(){
            //some functionality
        }

   });

How to call somefunction() from the above onDeviceready() function?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
kondal
  • 358
  • 1
  • 6
  • 22

3 Answers3

13
FCELB.app.getController('LoginController').somefunction();  

Where

FCELB - Application name

LoginController - Name of the controller

somefunction - Function name

Viswa
  • 3,211
  • 5
  • 34
  • 65
1

If your controller classes share some behaviour, you might also want to look at ExtJS mixins

player
  • 610
  • 6
  • 15
0

Try this:

document.addEventListener("deviceready", this.somefunction, false);

or

var self = this;
document.addEventListener("deviceready", function(e) { self.somefunction(e); }, false);
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176