繁体   English   中英

未检测到按钮单击

[英]Button click not detected

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

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

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

这是代码;

初始化:函数(应用程序){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);
    }
});

控制器

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');
        });
    }
});

两种可能性:

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

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

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

编辑

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

除了添加[action=buttonclick]部分之外,您已正确设置了侦听器。 这是此文档

'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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM