繁体   English   中英

在ExtJS 5.1中触发自定义事件

[英]Firing a custom event in ExtJS 5.1

我一直在尝试使用模式窗口成功上传文件时触发自定义事件。 主页上的网格会监听事件,并在成功上传文件后重新加载其存储。 问题是,网格永远不会捕获此事件。

我认为我对自定义事件的工作原理有基本的误解。 我应该采取什么步骤才能重回正轨?

SomeCommonUtilityClass.js

upload: function(args) {
    Ext.create('Ext.window.Window', {

    /* form with some controls */
        buttons: [{
            text:'Upload',
            handler: function() {
                var win = this.up('window');
                var form = this.up('form').getForm();
                form.submit ({
                    url: myAjaxCall,
                    success: function() {
                        /* fire event here */
                        win.fireEvent('uploadSuccess');
                    },
                    failure: function() {
                        /*...*/
                    }
                });
            }
        }, 
    /* etc. */
    });
}

SomeOtherFileView.js

{
    xtype:'grid',
    itemId:'uploadedGrid',
    listeners: {
        uploadSuccess: 'reloadUploadStore'
    },
    bind: {
        store:'{form}'
    },
    columns:[/*...*/]
}

SomeOtherFileViewController.js

reloadUploadStore: function() {

    console.log("My event fired!") // Never gets here.
    /* .... */
    store.load({
        params: ({
            a: "a",
            b: "b"
        });
        callback: function() {
            /* do more stuff */
        }
    });
}

SomeCommonUtilityClass

win.fireEvent('uploadSuccess');

自定义事件和监听它的控制器的示例:

SomeOtherFileViewController

init: function() {
        this.listen({
            // We are using Controller event domain here
            controller: {
                // This selector matches any originating Controller
                '*': {      
                    uploadSuccess: 'reloadUploadStore'
                }
            }
        });
    },
    reloadUploadStore: function() {
        //your code
    }

或者,如果您想传递参数:

win.fireEvent('uploadSuccess',extraArgument);

控制器代码是相同的。 仅您的函数定义会更改:

reloadUploadStore: function(yourArgument) {
    //Do your stuff with extraArgument
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM