绑定激活事件到网格面板Extjs4

问题描述 投票:2回答:1

我想问我可以在哪里向网格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

并且适用于click事件:

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 
        }
});
javascript extjs extjs4 dom-events
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'); } } }); } });

注意,仅当使用选项卡面板显示时,才会在面板上调用激活事件。当通过单击选项卡激活面板时,将调用该事件。
© www.soinside.com 2019 - 2024. All rights reserved.