【发布时间】:2020-04-12 19:59:58
【问题描述】:
我是 SAPUI5 的新手,正在尝试获取 SAPUI5 中的 RadioGroupButton 的选定按钮索引。
这样做的原因是为了隐藏或显示更多调查问题。并且表单基于两种语言,所以最好获取索引而不是 selectedButton 的文本。
这是我的 XML 和控制器代码。感谢任何帮助,因为我不明白为什么它无法识别控制台中的按钮索引并显示它未定义!
XML
<VBox class="sapUiMediumMargin">
<VBox id="Q1">
<Label labelFor="rgb1" text="{i18n>Q1}" />
<RadioButtonGroup id="rbg1" columns="2" width="100%">
<RadioButton id="RB1-1" text="{i18n>radio.button.no}" select="onSelect"/>
<RadioButton id="RB1-2" text="{i18n>radio.button.yes}" select="onSelect"/>
</RadioButtonGroup>
<!--Small Margin-->
<HBox class="sapUiSmallMargin"/>
</VBox>
控制器
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/Element",
"sap/m/MessageToast"
], function(Controller, Element, MessageToast) {
"use strict";
return Controller.extend("aaaa.comform.controller.view1", {
onSelect: function() {
var oRBGroup = this.getView().byId("rbg1");
var oButtonSelectedIndex = oRBGroup.getSelectedButtonIndex();
var oVBox1 = this.getView().byId("Q2"); // another Hidden question to be shown if answer is Yes
if (oButtonSelectedIndex === 1)) { // 1 means answer is Yes
oVBox1.setVisible(true);
// console.log(getSelctedButton);
} else {
oVBox1.setVisible(false);
}
}
});
});
【问题讨论】:
标签: javascript controller sapui5