4

私は大きなアプリを持っているので、app.js には何も追加しませんでした:

stores: []
controllers: []
views: []
models: []

その中には、アプリケーションを作成するために必要なものだけがあります。では、ノード (左側のパネル) をクリックしたときに、必要なコントローラーを作成し、そのコントローラーにモデル、ビュー、ストアなどをロードするにはどうすればよいでしょうか? コントローラーを呼び出すだけで十分ですか(コントローラーにインポートされているため)?

何かのようなもの

Ext.create('MyApp.path.SomeController');

controllers: []app.jsに追加するのと同じように追加されますか?

4

2 に答える 2

3

私の app.js から (つまりthis、Ext JS アプリケーションです):

addController: function (name) {
        var c = this.getController(name); //controller will be created automatically by name in this getter 
        //perform the same initialization steps as it would have during normal ExtJs process
        c.init(this);
        c.onLaunch(this);
    }

nameクラス名です...

同様に、他のコントローラーからアプリケーションインスタンスのハンドルを取得できることを思い出してください。this.application

于 2012-12-04T22:01:29.410 に答える
2

私のコードは、Jenson のコードと非常によく似ています。

// This function loads a controller dynamically and returns its first view
// Note: We don't call onLaunch(this) here. This method might be called during 
// bootstrap (like if there's a cookie with the recent page), after which 
// the application itself will call onLaunch (once out of the Launch method).
// The other issue is that the view is not added when this method is called
// and we might need to reference the view withing onLaunch, so this is the
// wrong place to call on Launch). Currently we're not relying on onLounch 
// with controllers.
dynamicallyLoadController: function( aControllerName )
{
    // See if the controller was already loaded
    var iController = this.controllers.get(aControllerName);

    // If the controller was never loaded before
    if ( !iController )
    {    
        // Dynamically load the controller
        var iController = this.getController(aControllerName);

        // Manually initialise it
        iController.init();
    }

    return iController;
},

loadPage: function( aControllerName )
{
    // save recent page in a controller
    Ext.util.Cookies.set( 'RecentPage', aControllerName );

    var iController   = this.dynamicallyLoadController( aControllerName ),
        iPage         = iController.view,
        iContentPanel = this.getContentPanel(),
        iPageIndex    = Ext.Array.indexOf(iContentPanel.items, iPage);

    // If the page was not added to the panel, add it.
    if ( iPageIndex == -1 )
        iContentPanel.add( iPage );

    // Select the current active page
    iContentPanel.getLayout().setActiveItem( iPage );
},
于 2012-12-04T22:11:24.747 に答える