控制器中未接收到来自视图的Sencha Touch FireEvent



我在视图中定义了这个:

视图:

Ext.define("MyApp.view.Welcome", {
extend: 'Ext.Panel',
alias: 'widget.welcomeview',

config: {
///...items... removed lines for brevity.. 
{
xtype: 'button',
id : 'btnSignInNow',
text: 'Sign In Now',            
listeners: {
tap: function() {
this.fireEvent("onSignInNowTap", this);
console.log("onSignInNowTap fired"); /// <-- I see this in console.log
}
}
}

我可以在日志中看到这个。但在我的控制器中,它没有接收到事件。有人能说明这件事吗?

控制器:

config: {
refs: {
welcomeView: 'welcomeview'
},
control: {
welcomeView: {
onSignInNowTap: function () {
alert('bla!');  <!-- I Don't see this in console.log
}
}
}
}

我很感激我可能错过了什么,但有什么方法可以调试,以找出这个事件是如何/在哪里丢失或被忽略的吗?

尝试

this.parent.fireEvent("onSignInNowTap", this);

而不是

this.fireEvent("onSignInNowTap", this);

这样,父视图将触发事件而不是按钮。有时,若按钮嵌套在里面很深,你们可能不得不做一些类似的事情

this.parent.parent.parent....fireEvent("onSignInNowTap", this);

在initialize中编写视图的监听器,您将在初始化中获得的参考

Ext.define("MyApp.view.Welcome", {
extend: 'Ext.Panel',
alias: 'widget.welcomeview',

initialize:function(){
this.callParent();
listeners: {
tap: function() {
this.fireEvent("onSignInNowTap", this);
console.log("onSignInNowTap fired");
}
}
}

谢谢ThinkFloyd。你的解决方案奏效了。我不得不使用这个。parent.fireEvent(…),然后控制器能够捕捉到它…

最新更新