0

I have a large scale application with lots of views, models, stores in it. Till now i am able to manage all the functionality to run from functions, events withing the views itself. I have never used controller to handle the entire application.

Please let me know how to use controllers to handle each and every component in the app. And there are some components that are dynamically being generated. How to add listeners these components on demand.

Please tell me about controllers much!

Thanks in advance :)

Anand Singh
  • 317
  • 5
  • 8
  • 22

1 Answers1

2

Controllers use event selectors to handle events through an event bus, so handling events is built in to the component structure.

A controller typically looks like:

Ext.define('MyApp.controller.Foo', {

    init: function() {
        this.control({
            'some_selector': {
                someevent: this.onSomething
            }
        });
    },

    onSomething: function() {}

});

The selector is an Ext.ComponentQuery selector, so if a component that matches that selector fires a particular event, it will call your method. There's plenty of information about selectors in the docs.

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
  • Thank you.I have created a controller to listen to a particular event for a specific component. And I have created another controller to act same as above on different component. But the second one didn't work. My question is is Can we have only one controller per application? I would like to have controllers for each individual module. Tell me is it possible? – Anand Singh Aug 26 '13 at 11:40
  • You can have as many controllers as you like. Be sure to add it to the controllers configuration for the app. – Evan Trimboli Aug 26 '13 at 13:04