2017-07-13 92 views
0

我有一个观点SAP UI5 DOM操作

<mvc:View controllerName="quiz.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" 
    xmlns="sap.m"> 
    <App> 
     <pages> 
      <Page title="{i18n>title}"> 
       <content> 
        <Text text="{questions>/question/text}"/> 
        <RadioButtonGroup columns="5" class="sapUiMediumMarginBottom"> 
         <buttons> 
          <RadioButton id="RB3-1" text="{questions>/question/option/1}"/> 
          <RadioButton id="RB3-2" text="{questions>/question/option/2}"/> 
          <RadioButton id="RB3-3" text="{questions>/question/option/3}"/> 
          <RadioButton id="RB3-4" text="{questions>/question/option/4}"/> 
         </buttons> 
        </RadioButtonGroup> 
        <Button text="Default" press="onPress" /> 
       </content> 
      </Page> 
     </pages> 
    </App> 
</mvc:View> 

,其中有是有4个选项的问题。我正在寻找显示按下按钮后立即选择的4个无线电框中的一个。

sap.ui.define([ 
    "sap/ui/core/mvc/Controller", 
    "sap/m/MessageToast" 
], function(Controller,MessageToast) { 
    "use strict"; 

    return Controller.extend("quiz.controller.View1", { 

     onPress : function (evt){ 
      // MessageToast.show(); over here i want to show the butoon which is pressed 
     } 
    }); 
}); 

我如何使用基本javascript document.getElementById()尝试处理DOM。但它不是在这里工作

回答

0

你需要给id来:

<RadioButtonGroup id="IDRadioButtonGroup" 

和访问它的按键方法:

onPress: function(){ 
    var oIDRadioButtonGroup = this.byId("IDRadioButtonGroup"); 
    console.log("BUTTON: " + oIDRadioButtonGroup.getSelectedButton()); 
} 

这里是example