如何将组件方法绑定到 ExtJS 中的 ViewModel?

How can I bind a component method to a ViewModel in ExtJS?

在 ExtJS 6.02 中,如果我有这个:

Ext.define('MyController', {
     extend : 'Ext.app.ViewController'
   , alias  : 'controller.myWindowController'
   , onShow: function() {
       console.log('IT SHOWS!');
   }
});

Ext.define('MyWindow', {
     extend: 'Ext.window.Window',
     controller: 'myWindowController',
     show: 'onShow'
});

ExtCreate('MyWindow', {}).show();  // Gives error here, `show` is a string now!

如何将组件方法绑定到控制器?
还是只能绑定事件?

您正在做的是覆盖 show method. Instead, it seems like you want to listen for when show is fired... to do that, you'd tap into the listeners config, and listen for the show 事件,如下所示:

Ext.define('MyWindow', {
    extend: 'Ext.window.Window',
    controller: 'myWindowController',
    listeners: {
        show: 'onShow'
    }
});