PDA

View Full Version : Call function from init



bstras21
20 Nov 2011, 6:17 PM
Just wondering if anyone knows how to call a function from the controllers init function?



init: function() {
if(1==1){
this.getApp;
}
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});
},
getApp: function() {
console.log('getApp called');

}


I would like to run the getApp function from init.

vitorgomes
20 Nov 2011, 7:05 PM
init: function() {
if (1 == 1) {
this.getApp;
}
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});
},


getApp: function() {
console.log('getApp called');
}

bstras21
20 Nov 2011, 7:11 PM
That function is actually outside the init function and I cant move that function outside of scope because I need to access certain properties. Thanks for the reply.

AndreaCammarata
21 Nov 2011, 1:50 AM
Just wondering if anyone knows how to call a function from the controllers init function?



init: function() {
if(1==1){
this.getApp;
}
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});
},
getApp: function() {
console.log('getApp called');

}


I would like to run the getApp function from init.

You forgot the bracket:



init: function() {
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});


this.getApp();
},


getApp: function() {
console.log('getApp called');
}

bstras21
22 Nov 2011, 6:32 AM
I have tried that too and it doesn't call the function, nothing happens.

AndreaCammarata
22 Nov 2011, 6:34 AM
Could you please post more code of your app?

bstras21
22 Nov 2011, 6:40 AM
Ext.define('myApp.controller.LoginController', {
extend: 'Ext.app.Controller',
views: ['LoginForm'],
stores:['LanguageStore'],
refs: [{
ref: 'loginButton',
selector: '#loginButton'
},{
ref: 'loginLanguage',
selector: '#loginLanguage'
}],
init: function() {
if(1==1){
this.getApp; //not working
}
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});
},
getApp: function() {
console.log('Punch app called from init');

},
getLanguageApp: function(){
console.log('language pressed');

}
});

AndreaCammarata
22 Nov 2011, 6:43 AM
Ext.define('myApp.controller.LoginController', {
extend: 'Ext.app.Controller',
views: ['LoginForm'],
stores:['LanguageStore'],
refs: [{
ref: 'loginButton',
selector: '#loginButton'
},{
ref: 'loginLanguage',
selector: '#loginLanguage'
}],
init: function() {
if(1==1){
this.getApp; //not working
}
this.control({
'#loginButton': {
tap: this.getApp,
scope: this
},
'#loginLanguage': {
tap: this.getLanguageApp,
scope: this
}
});
},
getApp: function() {
console.log('Punch app called from init');

},
getLanguageApp: function(){
console.log('language pressed');

}
});




Sorry, but from your code I still see that you didn't add the brackets..you are calling a function so you need to call



this.getApp();


However, instead of calling that function, if you place an alert, does it show?

bstras21
22 Nov 2011, 6:49 AM
I did try using () too but I get this error:

Uncaught TypeError: Cannot call method 'getValue' of undefined

I am able to console.log('I am in the init function')

AndreaCammarata
22 Nov 2011, 6:52 AM
Try to make this test:
Instead of calling the "getApp()" function, call the "getLanguageApp()" method and see if that one works.

bstras21
22 Nov 2011, 6:53 AM
However, I am not able to reference my refs. Do I need to pass something to the function?

bstras21
22 Nov 2011, 6:53 AM
However, I am not able to reference my refs.
For instance I can't do this now:

var user = Ext.getCmp('formUser').getValue();

Do I need to pass something to the function?