2013-07-26 15 views
2

我使用extjs 4作爲單選按鈕。代碼如下如何使用extjs 4獲取radiogroup檢查值?

var mychkbxgrp = Ext.create('Ext.form.RadioGroup',{ 
    fieldLabel: 'Layer', 
    columns: 1, 
    items:[{ 
    boxLabel: 'District', name: 'rb', inputValue: 'district',itemId:"DIS" 
    },{ 
    boxLabel: 'SubDistrict', name: 'rb', inputValue: 'Subdistrict',itemId:"sub" 
    },{ 
    boxLabel: 'Village', name: 'rb', inputValue: 'Village' 
    },{ 
    boxLabel: 'Road', name: 'rb', inputValue: 'Roads' 
    },{ 
    boxLabel: 'Point', name: 'rb', inputValue: 'POINT' 
    }], 
    listeners: { 
    change : function(){ 
     alert(this.getValue()); 
     } 
    } 
    }); 

我想獲取檢查後的單選按鈕的值。爲此,我使用了聽衆但不工作。我是對的還是需要用其他方式。請幫助我一樣。

回答

1

我已經嘗試了很多解決方案,並且只有一個工作。希望它可以幫助

listeners: { 
    change : function(obj, value){ 
     alert(value.individual); 
     } 
    } 
2

您的代碼看起來不錯。更改事件正在被解僱。只有改變你必須做的是

listeners: { 
    change : function(obj, value){ 
     alert(value.rb); 
     } 
    } 

其中value.rb會給你所選的單選按鈕的值。

+0

在你的代碼,如果你只需要改變'警報(this.getValue())''要警惕(this.getValue ().rb)',你就完成了。 –

+0

謝謝。有效。 – Pari

0

這也可以寫成一般來處理所有的無線電組。值(在我的例子中使用radioGroup中)是RadioGroup中,所以你可以使用

getChecked()
像這樣:

listeners: { 
    change: radioGroupHandler 
} 

... 

function radioGroupHandler(obj, radioGroup) { 
    var checked = radioGroup.getChecked(); 

    if (checked.length) { 
     alert(radioGroup.getChecked()[0].getValue()); 
    } else { 
     alert('nothing checked'); 
    } 
}