0

ビューでアニメーションを実行しているコントローラーがあります。アニメーションが完成したらgoToMainApp、コントローラーでメソッド ( と呼ばれる) を実行する必要があります。私のアニメーション完了リスナーが呼び出されます-問題はありません...しかし、メソッドの呼び出しは失敗します。コントローラーは次のとおりです。

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

    config : ....
    init : ......

    goToMainApp : function() {
        console.log('Redirecting to main application');
        do important stuff here....;
    },

    tryLogin : function() {
        this.getCredentialsForm().submit({
            success : function(form, action) {
                console.log('login successful');

                // fade out the login form element
                var form = Ext.ComponentQuery.query("loginview")[0];
                form.getEl().fadeOut({
                    duration : 500,

                        listeners : {
                            afteranimate : function() {
                                console.log('login successful');  // WORKS!!!
                                this.goToMainApp();  // FAILS!!!
                            }
                    }
                });

            },
            failure : .....
        });
    }
});

私の問題はthis、呼び出しthis.goToMainApp();の がコントローラーではなくアニメーションオブジェクトであることだと思います...しかし、それを修正する方法がわかりません。

4

1 に答える 1

3

リスナーにスコープを追加するだけです:

scope: this

ドキュメントの例:

        tryLogin : function() {
        this.getCredentialsForm().submit({
            scope : this,    // Sets scope of the form handler to the controller
            success : function(form, action) {
                console.log('login successful');

                // fade out the login form element
                var form = Ext.ComponentQuery.query("loginview")[0];
                form.getEl().fadeOut({
                    duration : 500,

                        listeners : {
                            scope : this, // Now also sets it to controller
                            afteranimate : function() {
                                console.log('login successful');  // WORKS!!!
                                this.goToMainApp();  // FAILS!!!
                            }
                    }
                });

            },
            failure : .....
        });
于 2012-12-04T18:27:14.603 に答える