在extjs中如何获得所选单选按钮的实际值?

时间:2013-01-07 09:06:00

标签: extjs radio-button

我在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);                                         


            }
                                  }

                              }
                              ]

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

1 个答案:

答案 0 :(得分: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;
  }
}