【问题标题】:ExtJS 4 - Radiogroup listener event fireExtJS 4 - Radiogroup 监听事件触发
【发布时间】:2013-07-25 06:31:50
【问题描述】:

我有一个无线电组如下:

{
                    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;
            }
        }
    }

【问题讨论】:

  • 你的问题不清楚,我不太明白你在这里问什么。如果change 事件未触发,您如何在控制台中看到某些内容?
  • 亲爱的埃文,我犯了一个错误,在switch 语句中值应该是字符串格式,因此没有触发更改事件。

标签: extjs extjs4 extjs4.2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多