收听单选按钮

时间:2012-01-11 12:19:17

标签: extjs radio-button listener

我想在工具栏中添加3个radiobutton,如下所示:

dockedItems: [
            {
                xtype: 'toolbar',
                dock: 'top',
                items: [
                    {
                        xtype: 'radiogroup',
                        width: 500,
                        fieldLabel: 'Show',
                        items: [
                            {
                                xtype: 'radiofield',
                                id: 'all',
                                name: 'show',
                                boxLabel: 'All vehicles',
                                checked: true
                            },
                            {
                                xtype: 'radiofield',
                                id: 'online',
                                name: 'show',
                                boxLabel: 'Online vehicles'
                            },
                            {
                                xtype: 'radiofield',
                                id: 'offline',
                                name: 'show',
                                boxLabel: 'Offline vehicles'
                            }
                        ]
                    }
                ]
            }
        ]

我想为这些按钮使用一个监听器。当有人点击离线我想加载internals.load({url:internals / offline.json});

我无法让它发挥作用。有什么建议/帮助吗?

由于

1 个答案:

答案 0 :(得分:7)

试试这个:

{   
    xtype: 'radiogroup',
    width: 500,
    fieldLabel: 'Show',
    items: [
        {
            xtype: 'radiofield',
            id: 'all',
            name: 'show',
            boxLabel: 'All vehicles',
            checked: true,
            inputValue: 'all'
        },
        {
            xtype: 'radiofield',
            id: 'online',
            name: 'show',
            boxLabel: 'Online vehicles',
            inputValue: 'online'
        },
        {
            xtype: 'radiofield',
            id: 'offline',
            name: 'show',
            boxLabel: 'Offline vehicles',
            inputValue: 'offline'
        }
    ],
    listeners: {
        change: function(field, newValue, oldValue) {
            var value = newValue.show;
            if (Ext.isArray(value)) {
                return;
            }
            if (value == 'offline') {
                // do something
            }
        }
    }
}