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

her*_*iam 6 javascript forms extjs extjs4

我已经按照基本程序获取我的单选按钮表单的选定值.

        ....
        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' ....
Run Code Online (Sandbox Code Playgroud)

我用过的方法如下:

Ext.getCmp('filter_form').getForm().getValues()['timespan']
Run Code Online (Sandbox Code Playgroud)

但是当我将它运行到控制台时,我得到了这个词,而不是获得所选按钮的值on.是什么赋予了?!我已经尝试了几种不同的getValues,getForm等组合,但我总是以ontrue或者结束false.这里发生了什么?

MMT*_*MMT 5

尝试设置inputValue无线电的属性.哪个是应该生成的输入元素的value属性的值,并且应该在作为表单的一部分提交时用作参数值.

{
        xtype          : 'radiofield',
        name           : 'timespan',
        inputValue     : '30',
        hideEmptyLabel : false,
        boxLabel       : '30 days'
}
Run Code Online (Sandbox Code Playgroud)

然后它可以作为

Ext.ComponentQuery.query('[name=timespan]')[0].getGroupValue();
Run Code Online (Sandbox Code Playgroud)

参考docs getGroupValue


her*_*iam 4

弄清楚了!原来我的extjs示例代码有错误!

value改为inputValue. 摘自 Sencha 文档inputValue

该值应进入生成的输入元素的 value 属性,并且在作为表单的一部分提交时应用作参数值。默认为:“开”

啊哈!!因为我没有指定“真实”值,所以它默认为on.

使用 extjs 示例/示例代码时要小心!