2016-06-27 105 views
0

我sap.m單選按鈕組在我view.xml用SAP UI5單選按鈕組

<m:RadioButtonGroup valueState="" select="changeRegion()"> 
<m:buttons> 
<m:RadioButton id="rb-S" text="S"/> 
<m:RadioButton id="rb-MW" text="MW"/> 
<m:RadioButton id="rb-NE" text="NE"/> 
<m:RadioButton id="rb-W" text="W"/> 
</m:buttons> 
</m:RadioButtonGroup> 

在我Controller.js

changeRegion: function(e){ 
    console.log(e.getParameter('selectedIndex')); 

    } 

我能夠訪問選定的指標單選按鈕。有什麼辦法可以獲得所選單選按鈕的文字?

回答

1

這絕對有可能。您已經有了索引,現在您只需要收集單選按鈕並選擇具有相應索引的radion按鈕。一旦你有了這個單選按鈕,你可以閱讀它的文本。

這是怎麼可以這樣做:

var idx = e.getParameter("selectedIndex"); 
var button = e.getSource().getButtons()[idx]; 
var txt = button.getText(); 

或簡稱:

var txt = e.getSource().getButtons()[e.getParameter("selectedIndex")].getText() 

您可以檢查出this jsbin看到它在行動

0

我想我發現了一個不同選項來閱讀選定的單選按鈕文本..只要有人需要它。

您需要一個ID爲您的單選按鈕組,如:

<m:RadioButtonGroup id='radioButtonGroup' valueState="" select="changeRegion()"> 
<m:buttons> 
<m:RadioButton id="rb-S" text="S"/> 
<m:RadioButton id="rb-MW" text="MW"/> 
<m:RadioButton id="rb-NE" text="NE"/> 
<m:RadioButton id="rb-W" text="W"/> 
</m:buttons> 

然後你就可以從選定的單選按鈕的文字是這樣的:

var text = sap.ui.getCore().byId(this.createId("radioButtonGroup")).getSelectedButton().getText(); 
+0

近日獲悉替代到'sap.ui.getCore()。byId(this.createId(「radioButtonGroup」))'this.getView()。byId(「radioButtonGroup」)''。我讀過sap.ui.getCore()不推薦 –