2

我想问一下我可以在哪里向我的网格 MVC 添加一个侦听器。

当我这样做时,什么也没有发生:

Ext.define('myApp.view.reslist' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.reslist',
    store : 'resStore',
    listeners: {
          activate: {
            fn: function(e){ 
                console.log('reslist panel activated');
                  }
            }
           },
    dockedItems: [{
           xtype: 'pagbar',
           store: 'resStore',
           dock: 'top',
           displayInfo: true
       }],
       ..... rest of grid configs

它适用于点击事件:

listeners: {
          activate: {
            fn: function(e){ 
                console.log('reslist panel clicked');
                 }
          }
           }

注意:我的控制器的 init 仍然是空的:

Ext.define('myApp.controller.resControl', {
    extend: 'Ext.app.Controller',

    stores: ['resStore'],

    models: ['resModel'],

    views: ['reslist','pagbar'],

    init: function() {

            // nothing here 
        }
});
4

1 回答 1

3

视图的动作和事件进入其适当的控制器。我的视图仅包含用于构建和渲染组件的配置和必要方法。所有的事件处理程序、按钮上的操作等都在控制器中。这是我的控制器的样子:

Ext.define('myApp.controller.resControl', {
    extend: 'Ext.app.Controller',
    stores: ['resStore'],
    models: ['resModel'],
    views: ['reslist','pagbar'],
    init: function() {

        this.control({
            'reslist' : {
                activate: function(e) { 
                        alert('reslist panel activated');
                }               
            }
        });
    }
});

请注意,仅当您使用选项卡面板显示时,才会在面板上调用激活事件。当通过单击选项卡激活面板时调用该事件。

于 2011-05-22T05:39:43.987 回答