Ext Radiogroup- 선택한 무선 버튼의 값에 액세스하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/414529

  •  03-07-2019
  •  | 
  •  

문제

방사선 그룹에서 선택한 라디오 버튼의 값에 액세스하는 데 어려움이 있습니다. 포럼과 웹 주변의 다른 게시물에서 토론을 바탕으로 여러 가지 다른 접근법을 시도했습니다. 불행히도 운이 좋았거나 숙련되지 않았습니다. 다음 FormPanel 구성을 기반으로 누군가가 그룹 '메인 폰'에서 선택한 라디오의 가치를 얻는 방법을 보여줄 수 있기를 바랍니다.

감사!

Ext-JS 포럼에서 도움을 제공하지 않은 동안 StackoverFlow로부터 응답을 얻을 수 있음을 나타 내기 위해 업데이트하고 싶었습니다. stackoverflow로가는 길!

매트

function createForm(elem) {
var myForm2 = new Ext.form.FormPanel({
  renderTo:elem,
  width:425,
  frame:true,
  style:"margin: 10px auto 10px auto;",
  items: [{xtype:'fieldset',
            title: 'Contact Info',
            autoHeight:true,
            items :[new Ext.form.RadioGroup({
                        fieldLabel: 'Main Phone',
                        vertical: false,
                        id:"mainPhone",
                        items: [
                            {boxLabel: 'Home', name: 'id-1', inputValue: 'H', checked:true},
                            {boxLabel: 'Work', name: 'id-1', inputValue: 'W'},
                            {boxLabel: 'Other', name: 'id-1', inputValue: 'O'}
                        ]    

                    }),
                  new Ext.form.TextField({
                    id:"frm_CreateCustomerHomePhone",
                    fieldLabel:"Home Phone",
                    width:275,
                    allowBlank:true
                 }),
                 new Ext.form.TextField({
                    id:"frm_CreateCustomerWorkPhone",
                    fieldLabel:"Work Phone",
                    width:275,
                    allowBlank:true
                 })
                  new Ext.form.TextField({
                    id:"frm_CreateCustomerOtherPhone",
                    fieldLabel:"Other Phone",
                    width:275,
                    allowBlank:true
                 })
    ]}]});              
}
도움이 되었습니까?

해결책

이것은 거친 추측이지만, 이는 어떻습니까 :

myForm2.getForm().getValues()['id-1'];

다른 팁

방법 getValue() 라디오 그룹 자체에서 확인 된 객체를 반환합니다. 그렇지 않으면 정의되지 않은 반환됩니다.

(그건 그렇고, 상자에 대한 입력 value 대신 값을 설정하지만, 그것이 큰 차이를 만들지는 않지만, 마지막 "getValue"에 해당 될 수도 있습니다.) extjs 3.0을 사용하고 있습니다. 당신과 약간 다릅니다.

var checkedItem = Ext.getCmp('mainPhone').getValue();

if (checkedItem == undefined) return '';

return checkedItem.getGroupValue();
// The getGroupValue will return the value of the checked option in a group,
// unfortunately, it only seems to work on the items and not the radiogroup 
// itself

이 질문이 오래되었음을 알고 있지만 참조를 위해 이것을 추가하고 있습니다. 다음 snipit은 ext 2.2 Afaik에 유효합니다.

Ext.getCmp("mainPhone").items.get(0).getGroupValue();

lo-tan의 답변은 저를 위해 작동합니다. 나는 또한 extjs 2.2.1을 사용하고 있습니다. 이 코드를 사용하여 라디오 그룹에서 값을 얻습니다.

내 라디오 그룹 :

var begrens_sok = new Ext.form.RadioGroup({  
fieldLabel: 'Begrens søket',  
columns: 1,
name: 'sokspecs',
id:'sokspecs',
 items: [  
      {boxLabel: 'Scientific name', name: 'sokspec', inputVale:'SN'},
      {boxLabel: 'Norsk navngruppe', name: 'sokspec', inputValue:'NNG'},
      {boxLabel: 'Norsk navnart', name: 'sokspec', inputValue:'NNA'},
      {boxLabel: 'Prosjektsøk', name: 'sokspec', inputValue:'PROJ'},
      {boxLabel: 'Fritekst søk', name: 'sokspec', inputValue:'FSOK', 'id':'sokspec', checked: true}
 ]  
    });

확인 된 Radiobutton 값을 얻으려면 다음을 사용합니다.

var radiovalue=  Ext.getCmp('sokspecs').items.get(0).getGroupValue()

필드의 특정 가치를 얻으려면 사용하십시오.

myForm2.getForm().findField('id-1').getGroupValue();

이것이 너무 간단한 지 확실하지 않지만 'inputValue'속성을 사용하여 값 (ext 3.3.1)에 액세스 할 수있었습니다.

var radio = ...;
var value = radio.inputValue;

MVC를 사용하는 경우 ID를 사용하는 것을 무시하려고 할 것입니다. 따라서 변화에서 가치를 얻는 솔루션 중 하나는

change : function(radioButton, newValue, oldValue, eOpts){
        console.log(newValue.individual);
}
function get_radio_value()
{
    for( var i=0; i < document.myForm.mainPhone.length; i++ )
    {
       if( document.myForm.mainPhone[ i ].checked )
       {
           return document.myForm.mainPhone[ i ].value;
       }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top