当使用模态窗口成功上传文件时,我一直在尝试触发自定义事件。主页面上的网格侦听事件,并在成功上载文件时重新加载其存储。问题是,网格永远不会捕获此事件。
我认为我对自定义事件的工作方式存在根本性的误解。我应采取哪些步骤才能重回正轨?
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 */
}
});
}
答案 0 :(得分:2)
<强> 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
}