تحويلة RadioGroup - كيفية الوصول إلى القيمة المحددة راديو الزر ؟

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

  •  03-07-2019
  •  | 
  •  

سؤال

أواجه بعض الصعوبة في الوصول إلى قيمة اختيار زر الراديو في radiogroup.لقد حاول عدد من المناهج المختلفة استنادا إلى المناقشة في وظائف أخرى في المنتدى و في جميع أنحاء شبكة الإنترنت.للأسف لم الحظ (أو المهارات) بما فيه الكفاية للحصول على عمل.على أساس التالية FormPanel config كنت آمل شخص يمكن أن تبين لي كيفية الحصول على قيمة الراديو المحددة في مجموعة 'mainPhone'.

وذلك بفضل!

أردت تحديث تشير إلى أن كنت قادرا على الحصول على رد من ستاكوفيرفلوو حين EXT-شبيبة المنتديات لم تقدم لي أي مساعدة.طريقة للذهاب ستاكوفيرفلوو!

مات

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() على الراديو المجموعة نفسها سيعود الكائن الذي هو مؤكد إن وجدت, وإلا فإنه يعود معرف.

(بالمناسبة أنا تعيين القيمة بدلا من inputValue بالنسبة لي مربعات, على الرغم من أنني لا أعتقد أنه يجعل الكثير من الفرق ، ربما ذلك لا في الماضي "getValue"), أنا باستخدام extjs 3.0 ، radiogroup التكوين هو مختلفة قليلا من يدكم.

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 صالحة لمدة تحويلة 2.2 afaik.

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

الجواب من لو-تان يعمل بالنسبة لي.أنا أيضا باستخدام extjs 2.2.1 مثلي قد لا يكون لديك تحويلة.شكل.Formpanel ولكن فقط في مربع البحث و radiogroup.أنا استخدم هذا الرمز للحصول على قيمة من الراديو المجموعة.

الراديو المجموعة:

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}
 ]  
    });

للحصول على فحص زر راديو قيمة استخدام هذا:

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

إذا كنت ترغب في الحصول على قيمة محددة من مجال استخدام

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

لست متأكدا إذا كان هذا هو بسيط جدا ولكن كنت قادرا على الوصول إلى القيمة (في تحويلة 3.3.1) باستخدام 'inputValue' الملكية.

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

إذا كنت تستخدم MVC, ربما محاولة تجاهل باستخدام معرفات.حتى واحد من الحل ثم الحصول على قيمة في تغيير الحدث

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