Using more than one controller with ExtJS 4 MVC

后端 未结 2 1489
南笙
南笙 2020-12-13 22:53

Let\'s say I have a main controller, then my application has a controller for each \"module\". This main controller contains the viewport, then a header (with a menu) + a \"

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 23:08

    In main controller add child controller in the click event handler of menu

    Ext.define('MyAPP.controller.MainController',{
    ...
      init:function()
      {
        this.control({
         'menulink':
         {
            click:this.populateCenterPanel
         }
        });
      },
      populateCenterPanel:function()
      {
        this.getController('ChildController');
      }
    });
    

    In launch function add listener to controller add event like this -

    Ext.application({
    ...
      launch:function(){
        this.controllers.addListener('add',this.newControllerAdded,this);
      },
    
      newControllerAdded:function(idx, ctrlr, token){
        ctrlr.init();
      }
    });
    

    Now put code for dynamically embedding views in the viewport in init method of ChildController.

    Ext.define('MyAPP.controller.ChildController',{
    ...
      refs: [
        {ref:'displayPanel',selector:'panel[itemId=EmbedHere]'}
      ]
      init:function(){
        var panel=this.getDisplayPanel();
        panel.removeAll();
        panel.add({
          xtype:'mycustomview',
          flex:1,
          autoHeight:true,
          ...
        });
      }
    });
    

    HTH :)

提交回复
热议问题