2011-11-24 89 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一樣的問題。 –