View Full Version : can i self define a function in controller?
linuxyf
23 Nov 2011, 12:34 AM
i implement a page in MVC pattern, in my controller i want to call a self-defined function, but when i call it, catch exception as following:
Uncaught ReferenceError: deleteOneNumber is not defined.
deleteOneNumber: function(val) {
......
return val;
}
where can i place self-defined function in??? in controller, model, or view?
thanks
mitchellsimoens
23 Nov 2011, 9:53 AM
If it is application logic then in the controller it goes.
Ext.define('MyApp.controller.Main', {
extend : 'Ext.app.Controller',
init: function() {
this.control({
'button[action=save]' : {
tap : this.handleSave
},
'button[action=cancel]' : {
tap : this.handleCancel
}
});
},
handleSave: function(btn) {
var form = btn.up('form');
if (this.doFormValidation(form)) {
this.handleCancel(btn);
} else {
Ext.Msg.alert('Error', 'There was an error!');
}
},
handleCancel: function(btn) {
var form = btn.up('form');
//close floating panel
},
doFormValidation: function(form) {
var isValid = false;
//do some validation
return isValid;
}
});
So you can see, doFormValidation isn't used anywhere except within handleSave so it's a custom function. handleCancel is a hybrid... it's used as an event listener but also as a custom function.
linuxyf
24 Nov 2011, 7:15 PM
i see, thank for your relay.
Does this work on Ext JS 4? Because I get an error: TypeError: this.doFormValidation is not a function
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.