ExtJS 4 - Radiogroup侦听器事件触发

时间:2013-07-25 06:31:51

标签: extjs extjs4 extjs4.2

我有一个如下的放射组:

{
                    xtype: 'fieldset',
                    title: 'MÜŞTERİ TİPİ SEÇİMİ',
                    layout: 'anchor',
                    height: 80,
                    defaults: {
                        anchor: '100%'
                    },
                    items: [
                        {
                            xtype: 'radiogroup',
                            anchor: 'none',
                            layout: {
                                autoFlex: false
                            },
                            defaults: {
                                margin: '0 5 0 0'
                            },
                            cls: 'customer-radio-group',
                            items: [
                                {boxLabel: 'TÜM MÜŞTERİ', name: 'cstgrp', inputValue: '1'},
                                {boxLabel: 'HORECA', name: 'cstgrp', inputValue: '2'},
                                {boxLabel: 'TRADER', name: 'cstgrp', inputValue: '3'},
                                {boxLabel: 'SCO', name: 'cstgrp', inputValue: '4'},
                                {boxLabel: 'BRANŞ', name: 'cstgrp', inputValue: '5'},
                                {boxLabel: 'HEDEF GRUP', name: 'cstgrp', inputValue: '6'},
                                {boxLabel: 'CTG', name: 'cstgrp', inputValue: '7'}
                            ],
                            listeners: {
                                change: function (field, newValue, oldValue) {
                                    //var value = Ext.ComponentQuery.query('radiofield[name=cstgrp]');

                                    //console.log(newValue['cstgrp']);

                                    switch (newValue['cstgrp']) {
                                        case 1:
                                            break;
                                        case 2:
                                            break;
                                        case 3:
                                            break;
                                        case 4:
                                            break;
                                        case 5:
                                            break;
                                        case 6:
                                            break;
                                        case 7:
                                            console.log('CTG Secildi...');
                                            break;
                                    }
                                }
                            }
                        }
                    ]
                }

当我点击收音机时,我可以在控制台中看到所选的收音机输入值。但是,监听器中可用的change事件不会触发,也不会发生任何事情。我做错了什么吗?

修正:
来自radio的值是一个字符串,因此我们应该在switch语句中转换为整数或使用字符串,谢谢@rixo

        listeners: {
        change: function (field, newValue, oldValue) {
            //var value = Ext.ComponentQuery.query('radiofield[name=cstgrp]');

            //console.log(newValue['cstgrp']);

            switch (parseInt(newValue['cstgrp'])) {
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    console.log('CTG Secildi...');
                    break;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

switch语句在javascript中使用strict comparisons。所以你必须在你的情况下使用字符串而不是整数:

case '7':
    console.log('...');
    break;