2012-10-11 39 views
1

我正在使用radiogroup是和否我希望將點擊值發送到服務器。如何實現它?extjs:從單選按鈕獲取檢查值

我的代碼:

{ 
    fieldLabel: 'Striping', 
    xtype: 'radiogroup', 
    columns: [50, 100], 
    items: [{ 
     boxLabel: 'Yes', 
     name: 'rb', 
     id: 'stYes', 
     /*checked: true,*/ 
     inputValue: '1', 
     listeners: { 
      click: function() { 
       alert("Click 2!"); 
      } 
     } 

    }, { 
     boxLabel: 'No', 
     name: 'rb', 
     id: 'stNo', 
     inputValue: '2', 
     listeners: { 
      click: function() { 
       alert("Click 2!"); 
      } 
     } 
    }] 
} 
+0

警戒也沒有來臨 – Hemant

+0

在收音機上沒有'click'事件,請嘗試'check'事件。 http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.Radio-event-check – MMT

+0

在radiogroup上使用'defaults:{name:'rb'}'自動組內的所有無線電都像一個組一樣工作。 – A1rPun

回答

2

我覺得這樣的事情會的工作,我不能對此進行測試大氣壓。 單擊不會單選單選按鈕,您需要使用更改事件。你最好把聽衆放在你的小組上。然後,您不必爲組中的每個按鈕定義偵聽器。

注意:注意將id賦給組件,改用itemId或name。

{ 
     fieldLabel: 'Striping', 
     xtype:'radiogroup', 
     columns: [50, 100], 
     items: [{ 
      boxLabel: 'Yes', 
      name: 'rb', 
      id: 'stYes', 
      /*checked: true,*/ 
      inputValue: '1' 

     }, 
     { 
      boxLabel: 'No', 
      name: 'rb', 
      id: 'stNo', 
      inputValue: '2' 
     }], 
     listeners: { 
      change: function(radiogroup, newValue, oldValue, eOpts) { 
       alert(newValue.rb); 
      } 
     } 
    } 

例小提琴:http://jsfiddle.net/johanhaest/cpLvK/7/

+0

新值是一個對象,因此您可以通過 獲得價值newValue.inputValue –

+0

不是一個可行的解決方案。上面的註釋和解決方案以及 –

+0

其實它是一個工作解決方案... http://jsfiddle.net/johanhaest/cpLvK/7/ newValue是一個對象。 newValue.rb會顯示選定的值。 –

0

.individual將返回inputValue您在RadioGroup中的項目設置。

listeners: { 
     change: function(radiogroup, newValue, oldValue, eOpts) { 
      alert(newValue.individual); 
     } 
    }