且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ExtJS 4.1从另一个控制器调用一个控制器

更新时间:2022-03-23 23:03:31

我有意义的是,从表单中触发一个自定义事件,只需在你的控制器中听到它,就像你在这里说的:

It makes sense to me to fire a custom event from the form and simply listen to it in both your controllers, like what you said here:


看来我应该触发一个由
控制器侦听的独特事件

It seems like I should fire a unique event that is listened to by both controllers



// File: app/controller/Auth.js
attemptLogin : function() {
    var form = Ext.ComponentQuery.down('#loginpanel').form;
    if (form.isValid()) {
        form.submit({
        success : function(form, action) {
            // fire the event from the form panel
            form.owner.fireEvent('loginsuccess', form.owner);
        },

然后在每个控制器中 可以使用Controller#控件来监听它,如下所示:

Then in each of your controllers you can listen to it with Controller#control, like this:

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

    init: function() {
        var me = this; 

        me.control({

            '#loginpanel': {

                loginsuccess: me.someHandler

            }
        });
    },

    someHandler: function(form) {
        //whatever needs to be done
        console.log(form);
    }
}

然后将相同的东西添加到您的测验控制器:

And then add the same thing to your Quiz controller:

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

    init: function() {
        var me = this; 

        me.control({

            '#loginpanel': {

                loginsuccess: me.someOtherHandler

            }
        });
    },

    someOtherHandler: function(form) {
        //whatever needs to be done
        console.log(form);
    }
}



我在4.1.0中成功使用了这种方法和4.1.1

I've used this approach successfully in 4.1.0 and 4.1.1