[英]Firing a custom event in ExtJS 5.1
I have been trying to fire a custom event when a file has been successfully uploaded using a modal window. 我一直在尝试使用模式窗口成功上传文件时触发自定义事件。 A grid on the main page listens for the event and should reload its store when a file is successfully uploaded.
主页上的网格会监听事件,并在成功上传文件后重新加载其存储。 Problem is, the grid never catches this event.
问题是,网格永远不会捕获此事件。
I think I have a fundamental misunderstanding of how custom events work. 我认为我对自定义事件的工作原理有基本的误解。 What steps should I take to get back on track?
我应该采取什么步骤才能重回正轨?
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. */
});
}
{
xtype:'grid',
itemId:'uploadedGrid',
listeners: {
uploadSuccess: 'reloadUploadStore'
},
bind: {
store:'{form}'
},
columns:[/*...*/]
}
reloadUploadStore: function() {
console.log("My event fired!") // Never gets here.
/* .... */
store.load({
params: ({
a: "a",
b: "b"
});
callback: function() {
/* do more stuff */
}
});
}
SomeCommonUtilityClass SomeCommonUtilityClass
win.fireEvent('uploadSuccess');
Example of custom event and Controller that listen on it: 自定义事件和监听它的控制器的示例:
SomeOtherFileViewController 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
}
or if you want pass a argument: 或者,如果您想传递参数:
win.fireEvent('uploadSuccess',extraArgument);
Controller code is the same. 控制器代码是相同的。 Only your function definition changes:
仅您的函数定义会更改:
reloadUploadStore: function(yourArgument) {
//Do your stuff with extraArgument
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.