2011-05-21 51 views
2

我想问哪儿,我可以添加一个监听到我的网MVC绑定激活事件网格面板Extjs4

当我这样做没有发生:

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

注:我的控制器的初始化仍然是空的:

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

    stores: ['resStore'], 

    models: ['resModel'], 

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

    init: function() { 

      // nothing here 
     } 
}); 

回答

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

注意,激活事件被称为只有当您使用标签面板的显示面板上。当面板通过点击选项卡被激活时,该事件被调用。

+0

谢谢你abdel这很好,帮助这么多,我知道的活动事件,我使用标签面板 – cranberies 2011-05-22 16:39:18

+0

我之所以要激发事件处理程序的原因,是我想计算我的高度网格,因此它适合边框视口的中心面板,是吗? – cranberies 2011-05-22 16:45:50

+0

@Abdel im intrested在同一个问题,并试图dp你的建议,但它没有工作,没有发生任何想法为什么? – Armance 2011-07-25 16:42:11