Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening to events between view controllers

I am having trouble trying to figure out how to listen to events fired in one View Controller from another ViewController.

My grid component defines a Listener

selModel: {
    listeners: {
        selectionchange: 'onChemClick'
    }
},

and my ViewController(called chemslist) has the function that fires another event

onChemClick: function(view, selected) {
    console.log("before firing");
    this.fireEvent('canvasData', this, selected.length);
    console.log("after firing");
    console.log(selected);
}

I have another controller that actually listens to this event and shows the data.

Ext.define('view.canvas.CanvasController', {
extend: 'Ext.app.ViewController',
alias: 'controller.canvas',

listen: {
    controller: {
        chemslist: {
            canvasData: 'onCanvasData'
        }
    }
},

onCanvasData: function() {
    console.log("At Fire");
}

});

For some reason I can't figure out why the CanvasController is not able to listen to the event. I did also go through the Ticket example and looked at how the events are fired and other viewControllers listen to them.

Also What would be a best practice if a selection on a grid in one region causes a lot of changes in another panel?, should the event be fired as a global so that all the components would listen to it ? or should i listen to it in the main Controller(not a ViewController) and generate the components based on the event ?

Thanks!

like image 984
Jayaram Avatar asked May 14 '14 19:05

Jayaram


1 Answers

The docs say:

selectors are either Controller's id or '*' wildcard for any Controller.

Contrary to intuition, we are not supposed to assign any id or itemId to the controller we want to listen to but the id is automatically created by Application and the id equals to controller class name.

I've made simple example - button, 2 controllers C1 listening to button and C2 listening to C1.

like image 173
Saki Avatar answered Oct 11 '22 19:10

Saki