0


私は sencha touch 2.0 にかなり慣れていないので、疑問に思っていました:
各タブのコントローラーで 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
    }

});
4

1 に答える 1

-2

複数のコントローラーを定義し、アプリケーションで構成し、各コントローラーで次を使用します。

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

対応するタブ コントローラーで使用可能なコンポーネントの制御のみを構成します。

于 2012-01-18T12:12:05.007 に答える