簡體   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