简体   繁体   English

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

[英]Bind activate event to grid panel Extjs4

I want to ask where exactly I can add a listener to my grid MVC.我想问一下我可以在哪里向我的网格 MVC 添加侦听器。

When I do this nothing happens:当我这样做时,什么也没有发生:

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

and it works with the click event :它适用于点击事件:

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

note : the init of my controller is still empty :注意:我的控制器的初始化仍然是空的:

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

    stores: ['resStore'],

    models: ['resModel'],

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

    init: function() {

            // nothing here 
        }
});

Actions and Events of a view goes into its appropriate controller.视图的操作和事件进入其适当的控制器。 My views contain only the config and necessary methods used for building & rendering the component.我的视图仅包含用于构建和渲染组件的配置和必要方法。 All the event handlers, actions on buttons etc are in the controller.所有事件处理程序、按钮操作等都在控制器中。 Here is how my controller would look like:这是我的控制器的样子:

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

Note that the activate event is called on the panel only when you use tab panel display.请注意,仅当您使用选项卡面板显示时,才会在面板上调用 activate 事件。 The event is called when the panel gets activated by clicking on the tab.当通过单击选项卡激活面板时调用该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM