2011-11-24 91 views
0


,因为我非常新的煎茶触摸2.0我想知道:
如何创建与每个选项卡控制器的TabBarView?TabBarView多个控制器(最佳实践)

我的想法:
创建控制器onTabChange。但是必须有更优雅的方式?

我的第一种方法:

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

    views: [ 
     'TabBar', 
     'About' 
    ], 

    ref: [ 
    ], 

    requires: [ 
     'app.controller.About' 
    ], 

    init: function() { 
     // Create tabbar and listen for events 
     this.tabBarView = this.getTabBarView().create(); 
     this.tabBarView.addListener('activeitemchange', this.onActiveitemchange, this); 

     // Add views to tabbar 
     var aboutView = this.getAboutView().create(); 
     this.tabBarView.add(aboutView); 

     // TODO: Add more views 

     // Crate application listeners 
     this.application.addListener('changeTab', this.changeTab, this); 

    }, 

    /** 
    * Change tab (fired from views inside tabbar) 
    */ 

    changeTab : function() { 
     this.tabBarView.setActiveItem(0); 
    }, 

    /** 
    * Listen for tabchange an map controller to view 
    */ 
    onActiveitemchange : function(container, newView, oldView, e) { 
     console.info("tabchange"); 

     // Create appropiate controller 
     switch (newView.alias[0]) { 
      case 'aboutView': 
       var aboutController = this.application.getController('About'); 
      break; 

      // TODO: Add more breakpoints 

      default: 
      console.warn("No controller mapped to: "+newView.alias); 

     }; 

     // TODO: Remove old controller 
    } 

}); 

回答

-2

定义多个控制器,在您的应用程序配置它们,并在每个控制器使用以下命令:

init: function() { 
    this.control({ 
     'your selector': { 
      event: 'function-name to execute on event' 
     }, 
     .... 
    }); 
} 

在相应的可用组件,仅配置控制标签控制器。

+0

请你详细解释一下。我没有明白。 – fabian

+0

这并不能解决要求的内容。我有和@fabian一样的问题。 –