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

时间:2012-12-19 20:59:15

标签: 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',
           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
                }
            }
        }
    }

我很感激我可能错过了一些东西,但有什么方法可以调试以找出这个事件丢失或被忽略的方式/位置?

3 个答案:

答案 0 :(得分:2)

尝试

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

而不是

this.fireEvent("onSignInNowTap", this);

那样父视图将触发事件而不是按钮。 有时如果按钮嵌套在内部,你可能需要做类似这样的事情

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

答案 1 :(得分:0)

在初始化中写下你的视图的监听器, 您将在初始化

中引用 this
 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");
          }
       }
    }

答案 2 :(得分:0)

感谢ThinkFloyd。您的解决方案有效我不得不使用this.parent.fireEvent(...),然后控制器能够抓住它......