【问题标题】:In extjs how to get selected radio buttons actual value?在 extjs 中如何获取选定的单选按钮的实际值?
【发布时间】:2013-01-07 09:06:00
【问题描述】:

我在 extjs 工作。我正在显示 10 个问题及其相关选项。单击提交按钮时,我想检索选定的单选按钮值。我的视图形式为= QbqnsView.js

  Ext.define('Balaee.view.qb.qbqns.QbqnsView',
           {
        extend:'Ext.view.View',
        id:'qbqnsViewId',
        alias:'widget.QbqnsView',
        //store:'kp.PollStore',
        store:'qb.QbqnsStore',
        config:
        {
            tpl:'<tpl for=".">'+
                '<div id="main">'+
                '</br>'+
            //  '<b>Question :-</b> {pollQuestion}</br>'+
                '<b>Question :-</b> {question}</br>'+

                '<tpl for="options">'+     // interrogate the kids property within the data
                //'<p>&nbsp&nbsp<input type="radio" name="{optionId}">&nbsp{option}</p>'+
                 '<p>&nbsp&nbsp<input type="radio" name="{parent.questionId}">&nbsp{option}</p>'+
                //'<p>&nbsp&nbsp<input type="radio" name="{questionId}">&nbsp{option}</p>'+
                '</tpl></p>'+
                '<p>---------------------------------------------------------</p>'+
                '</div>'+
                '</tpl>',
            itemSelector:'div.main',    
        }

Qbqns.js=

 Ext.define('Balaee.view.qb.qbqns.Qbqns',   
        {
    extend:'Ext.form.Panel',
    requires:[
              'Balaee.view.qb.qbqns.QbqnsView'
              ],
              id:'qbqnsId',
              alias:'widget.Qbqns',
              title:'Qbqns',
              //height:400,
              items:[
                     {
                         xtype:'QbqnsView',
                                             },
                     ],//end of items square
                     buttons:[
                              {
                                  xtype:'button',
                                  fieldLabel:'Vote',
                                  name:'vote',
                                  formBind:true,
                                  text:'submit',
                                  // action:'voteAction',
                                  listeners: { 
                                      click: function(btn,e,eOpts) {
                                     var answers =               

    Ext.core.DomQuery.select("input[type='radio']:checked");
   console.log(answers);                                         


            }
                                  }

                              }
                              ]

所以在点击提交按钮时,它给我的价值是'输入,输入,......'。它没有给我实际的期权价值。那么如何检索所选选项的实际价值呢?请帮帮我

【问题讨论】:

  • 为什么不用ExtJS的单选按钮组件?
  • 感谢先生的回复。但我通过json文件接受问题及其选项来动态生成问题及其选项。那么如何使用单选按钮组件来动态创建问题及其选项呢?你能帮帮我吗

标签: extjs radio-button


【解决方案1】:

尝试以下代码来获取选中的单选按钮 -

//put value of {parent.questionId} in getElementsByName()
var inputs = document.getElementsByName(""); 
var radio = "";  
for (var i = 0; i < inputs.length; i++) {
  if (inputs[i].checked) {
    radio  = inputs[i].name;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多