简体   繁体   English

(extjs)获取表单中单选按钮的选定值。 没有返回值

[英](extjs) Get selected value of radio button in form. Not returning the value

I've followed the basic procedures for obtaining the selected value of my radio button form. 我已经按照基本程序获取我的单选按钮表单的选定值。

        ....
        xtype: 'radiofield',
        name: 'timespan',
        id: 'timespan',
        value: 7,
        checked: true,
        fieldLabel: 'Time Span',
        boxLabel: '7 days'
    }, {
        xtype: 'radiofield',
        name: 'timespan',
        value: '30',
        fieldLabel: '',
        labelSeparator: '',
        hideEmptyLabel: false,
        boxLabel: '30 days'
    }, {
        xtype: 'radiofield',
        name: 'timespan',
        value: '60',
        fieldLabel: '',
        labelSeparator: '',
        hideEmptyLabel: false,
        boxLabel: '60 days'
    }, {
        xtype: 'radiofield',
        name: 'timespan',
        value: 'all',
        fieldLabel: '',
        labelSeparator: '',
        hideEmptyLabel: false,
        boxLabel: 'All' ....

I've used methods like: 我用过的方法如下:

Ext.getCmp('filter_form').getForm().getValues()['timespan']

But when I run this to the console, instead of getting the value of the selected button, I get the word on . 但是当我将它运行到控制台时,我没有获得所选按钮的值,而是on了这个词。 What gives?! 是什么赋予了?! I've tried several different combos of getValues, getForm, etc, but I always end up with on or true or false . 我已经尝试了几种不同的getValues,getForm等组合,但我总是以ontruefalse What's going on here? 这里发生了什么?

try setting inputValue property of radio. 尝试设置inputValue属性。 Which is the value that should go into the generated input element's value attribute and should be used as the parameter value when submitting as part of a form. 哪个是应该生成的输入元素的value属性的值,并且应该在作为表单的一部分提交时用作参数值。

{
        xtype          : 'radiofield',
        name           : 'timespan',
        inputValue     : '30',
        hideEmptyLabel : false,
        boxLabel       : '30 days'
}

then it can be accessed as 然后它可以作为

Ext.ComponentQuery.query('[name=timespan]')[0].getGroupValue();

refer docs getGroupValue 参考docs getGroupValue

Figured it out! 弄清楚了! Turns out that my extjs sample code has an error! 原来我的extjs示例代码有错误!

I changed value to inputValue . 我将value更改为inputValue Taken from the Sencha Docs, inputValue is: 取自Sencha Docs, inputValue是:

The value that should go into the generated input element's value attribute and should be used as the parameter value when submitting as part of a form. 应该生成的输入元素的value属性中的值,并且应该在作为表单的一部分提交时用作参数值。 Defaults to: 'on' 默认为:'on'

Aha!! 啊哈! Because I hadn't specified a "real" value, it defaulted to on . 因为我没有指定“真实”值,所以它默认为on

Be careful when using the extjs examples/sample code! 使用extjs示例/示例代码时要小心!

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

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