未检测到按钮单击

时间:2012-07-24 14:00:17

标签: extjs4 extjs4.1 extjs-mvc

我有一个窗口,它包含一些文本字段和一个按钮。这是按钮的定义;               alias.widget: 'mywin',               ....

            {
                xtype: 'button',
                height: 40,
                width: 110,
                text: 'send',
                x: 58,
                y: 12,
                action: 'buttonclick'
            },

在我的控制器中,我将检测此按钮单击并显示console.log语句。

这是代码;

init:function(application){         this.control({

        'mywin button[action=buttonclick]': {
            click: this.butClick
        }
    });
},


butClick: function(button,record) {
    console.log('Button clicked');

这不会显示,我该如何解决?

更新

Ext.define('MyApp.view.MyWindowClass', {
    extend: 'Ext.window.Window',
    alias: 'widget.mywin',
    height: 340,
    id: 'mywinid',
    width: 728,
    layout: {
        type: 'absolute'
    },

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [

                {
                    xtype: 'textareafield',
                    height: 140,
                    width: 340,
                    fieldLabel: 'Name',
                    x: 370,
                    y: 80
                },
                {
                    xtype: 'button',
                    height: 40,
                    width: 210,
                    text: 'Save',
                    x: 480,
                    y: 240,
                    action: 'submitfeedback'
                },
                {
                    xtype: 'datefield',
                    id: 'dd',
                    readOnly: true,
                    fieldLabel: 'Today',
                    x: 10                  
                }
            ],
            listeners: {
                show: {
                    fn: me.onWindowShow,
                    scope: me
                }
            }
        });
        me.callParent(arguments);
    }
});

CONTROLLER

Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',
    models: [
        'MyController'
    ],
    stores: [
        'MyController'
    ],
    views: [
        'MyWindowClass',        
    ],
    init: function(application) {
        this.control({
            'mywin button[action=submitfeedback]': {
                click: this.butClick
            }
        });
    },
    butClick: function(button,record) {
        console.log('button clicked');
        });
    }
});

2 个答案:

答案 0 :(得分:3)

两种可能性:

  1. 这可能是一个错字,但你写了alias.widget: 'mywin'。这应该是alias: 'widget.mywin'

  2. 可能未加载控制器。在init函数的开头添加一个断点,看它是否运行。

  3. 除此之外,您的代码看起来是正确的。如果您发布更多上下文(例如,如何创建窗口,加载控制器,mywin的完整定义),我可以进一步检查它。

    修改

    您的大小写在选择器中是错误的。 myWin应为mywin

答案 1 :(得分:0)

除了添加[action=buttonclick]部分之外,您已正确设置了侦听器。 以下是docs

'mywin button': { // this line determines what view object you want to listen to
    click: this.butClick // this line determines what event you want to listen to
}