Ext JS 4单选按钮组选中事件

3

我正在使用FormPanel内的xtype创建一个extJS 4中的radioGroup。我尝试在选中单选框时立即启用/禁用文本字段。

{
xtype: 'radiogroup',
fieldLabel: 'Enable / Disable ',
columns: 2,
vertical: true,
items: [
     {boxLabel: 'Enable', name: 'formtype', inputValue: '1'},
     {boxLabel: 'Disable', name: 'formtype', inputValue:'2',checked:true},
    ]
 }

我不确定在哪里添加check/click事件的监听器。提前感谢你的帮助。

我尝试以这种方式添加,但为什么它会弹出两次alert()? - aswininayak
1
监听器: { "改变": function(field, newValue, oldValue, eOpts ){ alert(this.items); } } - aswininayak
2个回答

11
你需要处理每个单选按钮的“change”事件。当单选按钮改变(被选中)时,启用/禁用文本字段。
以下是一个示例:
Ext.create ('Ext.container.Container', {
    renderTo: Ext.getBody () ,
    items: [{
        xtype: 'textfield' ,
        id: 'tf' ,
        disabled: true ,
        fieldLabel: 'My Text'
    } , {
        xtype: 'radiogroup',
        fieldLabel: 'Enable / Disable ',
        columns: 2,
        vertical: true,
        items: [{
            boxLabel: 'Enable',
            name: 'formtype' , 
            inputValue: '1' ,
            listeners: {
                change: function (cb, nv, ov) {
                    if (nv) Ext.getCmp('tf').enable ();
                }
            }
        } , {
            boxLabel: 'Disable', 
            name: 'formtype', 
            inputValue:'2',
            checked: true ,
            listeners: {
                change: function (cb, nv, ov) {
                    if (nv) Ext.getCmp('tf').disable ();
                }
            }
        }]
    }]
});

你好


2

如果你将监听器的更改事件设置在单选按钮组本身上(而不是每个按钮上),那么你只需要处理一个事件。你的监听器/处理程序将被调用并传递newValoldVal。然后,你可以将newVal作为所选值获取。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接