【问题标题】:Bind activate event to grid panel Extjs4将激活事件绑定到网格面板 Extjs4
【发布时间】:2011-08-30 08:15:14
【问题描述】:

我想问一下我可以在哪里将侦听器添加到我的网格 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 
        }
});

【问题讨论】:

    标签: javascript extjs extjs4 dom-events


    【解决方案1】:

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

    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');
                    }               
                }
            });
        }
    });
    

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

    【讨论】:

    • 谢谢 abdel,这很好,帮助很大,我知道 activae 事件,我正在使用标签面板
    • 我想在激活事件上触发处理程序的原因是我想计算我的网格的高度,以便它适合边框视口的中心面板,对吗?
    • @Abdel 我对同一个问题很感兴趣,并试图提出您的建议,但没有奏效,什么也没发生……知道为什么吗?
    猜你喜欢
    • 1970-01-01
    • 2013-01-01
    • 2012-07-30
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 2012-02-11
    相关资源
    最近更新 更多