PDA

View Full Version : MVC Call function



elgreconiko
9 Aug 2012, 6:31 AM
Hi @ all,
how can i execute a function in a controller from a button in a view ?
thanks in advance..
My controller:

Ext.define('app.controller.MainController', {
extend : 'Ext.app.Controller',
views : ['MainPanel'],
init : function() {
console.log('mainController ==> successful loaded'
},
alert : function(alertText) {
console.log(alertText);
}
});

The Button in my View :

{ xtype : 'button',
itemId : 'btnLogout',
height : 40,
width : 60,
text : 'Logout',
x : 50,
y : 35,
handler : function() {
// Method to call teh function in my Controller
}

sword-it
9 Aug 2012, 6:55 AM
Hi,

See the sample code -

Controller -


Ext.define('MyApp.controller.Users', {
extend: 'Ext.app.Controller',

init: function() {
this.control({
'button [action=click]': {
click: function() {
alert('hi');
}
}
});
}
});





Ext.Loader.setConfig({
enabled: true
});
Ext.application({

name: 'rpc',
appFolder: 'MyApp',
controllers: ['Users'],
launch: function() {

console.log('Ext.application ~ launch'),
Ext.create('Ext.form.Panel', {
title: 'Simple Display',
autoHeight: true,
renderTo: Ext.getBody(),
layout: "column",
items: [{
xtype: "textfield",
fieldLabel: 'Name',
name: "a"
}],
buttons: [{
text: "Print DisplayField",
action: 'click'
}]
});

}
});



For more info read-http://www.sencha.com/learn/the-mvc-application-architecture/
(http://www.sencha.com/learn/the-mvc-application-architecture/) http://www.extjsframework.com/mvc/simple-mvc-application