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

Sencha touch 控制器中未接收到来自视图的Sencha Touch FireEvent,sencha-touch,sencha-touch-2,Sencha Touch,Sencha Touch 2,在我看来,这是一个定义: 查看: Ext.define("MyApp.view.Welcome", { extend: 'Ext.Panel', alias: 'widget.welcomeview', config: { ///...items... removed lines for brevity.. { xtype: 'button', id : 'btnSignInNow',

在我看来,这是一个定义:

查看:

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
                }
            }
        }
    }
Ext.define(“MyApp.view.Welcome”{
扩展:“Ext.Panel”,
别名:“widget.welcomeview”,
配置:{
///…项目…为简洁起见删除了行。。
{
xtype:'按钮',
id:'btnSignInNow',
文本:“立即登录”,
听众:{
点击:函数(){
this.firevent(“onSignenNowtap”,this);

console.log(“onSignenNowtap激发”);//将视图的侦听器写入初始化, 您将在“初始化”对话框中获得对该的引用

 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");
          }
       }
    }
试一试

而不是

this.fireEvent("onSignInNowTap", this);
这样,父视图将触发事件而不是按钮。 有时,若按钮嵌套在内部深处,您可能需要执行以下操作

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

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

侦听器正常,它已经在视图中的按钮上。我可以看到显示它调用firefevent的console.log。问题是在控制器中接收事件。请参阅我更新的示例(监听器实际上在按钮上)。是的,监听器是可以的。但是如果您想引用它,请使用
this.add([items])在initialize中添加项
并编写任何监听器..还有一件事使用
作用域:这个
用于在点击后调用的函数。好的,我想我现在明白了。你能改变你的示例来显示作用域:这个被使用的位置吗?我知道了!点击变成了一个有两个成员的对象(fn&scope)。再次感谢您的帮助。好的,很酷,我不知道您能做这件事。我下次会试试。
this.parent.parent.parent….fireEvent(“onSignnnowtap”,this);
::Apt解决方案,帮了我两次:-)您也可以使用
up()
像这样联系家长
this.up(“#parentId”)。fireEvent(“onSignnnowtap”,this);
。如果您可以使用父项的属性查询父项,这将更加清晰。
this.parent.parent.parent....fireEvent("onSignInNowTap", this);