3
votes

I'm using Extjs 5.1, I would like to invoke a method in a ViewController Here is my View:

Ext.define("bdociTabletProto.view.main.Main", {
extend: "Ext.container.Container",
requires: ['bdociTabletProto.view.main.MainController'],
controller: "mainController",

initComponent: function () {
    var me = this;
    me.layout = "border";
    ....
    me.items = [...];
    me.listeners = {
        afterlayout: 'onMainAfterLayout',
        scope: 'controller'
    };
    me.callParent(arguments);
}
});

and here is the ViewController where I implement the onMainAfterLayout method:

Ext.define("bdociTabletProto.view.main.MainController", {
extend: 'Ext.app.ViewController',
alias: 'controller.mainController',

onMainAfterLayout: function (container) {
    var me = this;
    var docNavigator = me.getView().docNavigator;
    var workflowActions = me.getView().workflowActions;
    docNavigator.setHeight(container.getHeight());
    docNavigator.setWidth(container.getWidth() / 4);
    workflowActions.setPosition((container.getWidth() - workflowActions.getWidth()) / 2, 0);
}
});

this throws an Exception: [E] Ext.util.Event.getFireInfo(): Unable to dynamically resolve scope for "afterlayout" listener on ext-comp-1010

At the first time I wrote the listener without scope, but after googling the problem, I found that in the new Version of Extjs (5.1) I should set the Scope property.

Without setting the scope property, the error is like that : Uncaught Error: No method named "onMainAfterLayout" on bdociTabletProto.view.main.Main

Any one can help me please?? Thank you

1

1 Answers

4
votes

I found the solution:

  • Add this in the ViewController

    control: { '#': { afterlayout: 'onMainAfterLayout' } },

  • remove the listeners from the view