0

In controller

listen: {
   global: {
     'ontest': 'ontestfunction'
   }
},

ontestfunction: function(){
    alert('oks 31');
}

In view

listeners: {
                element: 'element',
                click: function(){
                    Ext.GlobalEvents.fireEvent('ontest');
                }
     }

It is the only way I've found to work, you know some other way?

2 Answers 2

3

You can get any controller using Ext.app.Controller.getController.

Since application is derived from controller, all you have to know is the name of your app and the desired controller; and calling the function is a piece of cake:

var configController = MyAppName.app.getController("MyAppName.controller.Configuration");
configController.ontestfunction();
Sign up to request clarification or add additional context in comments.

Comments

1

Since you're using EXT 6, I assume you're using viewcontrollers and not controllers.

Ext is going to resolve the scope as the view's controller automatically, no need to write any extra code.

First make sure you define the viewcontroller as the controller of the view:

controller: 'aliasofviewcontroller'

after that you can basically assign any of the controllers functions to the handlers of the components on the view.

Let's say you have the following function in your controller:

onClickCustomHandler:function(e){
...
}

Using the following syntax, the function is going to get called every time you're button is clicked:

Ext.create('Ext.Button', {
    text: 'My button',
    handler: 'onClickCustomHandler'
});

Or using xtype:

{
   xtype:'button',
   text:'My button',
   handler: 'onClickCustomHandler'
}

For further reading: http://docs.sencha.com/extjs/6.0.2/guides/application_architecture/view_controllers.html

1 Comment

Thanks, this works now with dynamically generated components

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.