PDA

View Full Version : event handling (sending user events)



madmax797
25 Jun 2012, 1:59 PM
all:
newbie here.. question on firing user events

In one of my controller methods, i create a store and call load on it. In the 'load()' listener i have work to do, but i want to do it in 'controller's' method.(Reason : controller has other methods which i need to use). I am thinking of firing an event so the controller can listen for it and do the work.

MyController
{
init: function() {
this.application.addListener({
'loadEvent' : this.loadEventHandler
});
....
}
evHandler1: function() {
var myStore = Ext.create('store', //skipping the exact syntax
listeners: {
load: function() {
//here i want to fire an event, so my controllers method does the work
//this.application.fireEvent('loadEvent'); //this line gives error
}
}
myStore.load();
},
loadEventHandler: function()
{
//want to do the actual work here when the store got loaded.
}

khmurach
25 Jun 2012, 11:12 PM
You should
1. this.application.addEvents
2. this.application.fireEvent


//add event
this.application.addEvents('UsersStoreLoaded');

this.getUsersStore().on('load', function (store) {
this.log('store on load');
//fire event
this.application.fireEvent('UsersStoreLoaded', store);
}, this); // controller scope

//handle event
this.application.on('UsersStoreLoaded', function (store) {
this.log('app on UsersStoreLoaded');
});


Demo here http://ext4all.com/post/mvc-application-add-custom-events