2016-06-27 104 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()不推荐 –