extjsextjs5

How to add functions already defined to another controller


i have defined a couple of methods in one controller, which i one to factor, and use them in another controller, i tried :

in the second controller (Mine.view.DashboardController)

requires: [
            'Mine.view.SettingsMenuController'         
        ],

But the methods in the required controller (Mine.view.SettingsMenuController) are simply not seen by my Mine.view.DashboardController

What's the issue ?

Thanks


Solution

  • Put the shared methods in a class that extends Ext.app.ViewController Then create your other controller classes that extend your original class... OO programming....

    Ext.define("MyApp.ControllerOne", {
        extend: 'Ext.app.ViewController',
        alias: 'controller.controllerone',
        sharedFunction: function() {
            console.log("shareme");
        }
    });
    
    
    Ext.define("MyApp.ControllerTwo", {
        extend: 'MyApp.ConrollerOne',
        alias: 'controller.controllertwo'
    });
    
    
    
    Ext.define("MyApp.ControllerThree", {
        extend: 'MyApp.ConrollerOne',
        alias: 'controller.controllerthree'
    });