EXTJS 4 Control View Issue

I'm trying to figure out how to do the following but I'm a bit confused. I have a view which I call module:

Ext.define('MyApp.view.module.Module', {

  mixins : {
    observable :  'Ext.Util.Observable'
  },

  constructor : function(){
     this.addEvent('clickmodule');
     this.mixins.observable.constructor.call(this, config);
     this.init();
  }
   init : Ext.emptyFn
 });

Which this class extends:

 Ext.define('MyApp.view.module.MyModule', {
 extends : 'MyApp.view.module.Module',
 alias : 'widget.mymodule',

  init : function() {
       this.on('clickmodule', function(){
         alert('this is always fired so the event works');
       }, this)
       this.init();
  },

  runModule : function(){
     this.fireEvent('clickmodule');
  }
  });

So I have a base modue and then my real module which when runModule() is called just fires the event i created in the base class called clickmodule. This works and fire, i but a listener in the init() method which listens for the event to be fired and it works so I know it gets fired. The question is how do I get the Controlerl to listen to the event and do some action? I can't seem to find an example of how this is done? So for example I have this in my controller but don't think its correct and I'm not sure how to do this:

Ext.define('MyApp.controller.Desktop', {
 extends : 'Ext.app.Controller',
 refs : [
     ref : 'module',
     selector : 'mymodule'
  ],
 views : ['module.MyModule'],
 init : function(){
   this.control({
      'mymodule' : {
         clickmodule : this.onModuleClick
       }
   });
 },

 onModuleClick : function(){
     alert('this never gets called');
 }

});

So I know the event is fired since I put a listener in class and it gets called. But I'm not doing something right in the controller because it doesn't seem to be getting the event when fired. I think I'm missing something when setting up the this.control.


Turns out my MyApp.view.module.Module needs to extend Ext.Component. That's the only way I could get the event to trigger in the controller.

链接地址: http://www.djcxy.com/p/76396.html

上一篇: 如何在extjs 4.0中为按钮创建类似于拦截器的功能?

下一篇: EXTJS 4控制视图问题