ExtJs MVC中on和mon之间的区别

Vis*_*kia 2 model-view-controller extjs

我需要在extjs 4.1.3中的xtype:'panel'中添加click事件

但是我可以通过两种方式做到这一点。

  1. panel.mon(panel.getEl(), 'click', function(){ panel.fireEvent('click'); });

  2. panel.getEl().on('click',function(){ panel.fireEvent('click'); });

因此,在完成上述代码后,在控制器中我可以获取面板的click事件,并可以在其中执行操作。但是我无法理解这些方式之间的区别。我心中的另一个问题是哪种方法最好?请有人可以帮助我了解这个差异吗?提前致谢。

Eva*_*oli 5

mon当组件将事件绑定到我们要在组件销毁时要删除的对象时使用。例如:

// Some shared menu
var menu = new Ext.menu.Menu();

var p = new Ext.panel.Panel();
p.mon(menu, 'show', function(){
    p.update('Menu was shown');
});
// This automatically causes the show event on the menu
// to be removed, even though the menu wasn't touched
p.destroy(); 
Run Code Online (Sandbox Code Playgroud)

在您的情况下,组件将始终清理其元素,因此无论哪种方式都没有关系。