如何在不使用 RadioButtonGroup 的情况下在控制器中获取 RadioButton 文本?
How to get RadioButton text in controller without using RadioButtonGroup?
我的看法:
<FlexBox
alignItems="Start"
justifyContent="SpaceBetween">
<m:HBox alignItems="Stretch">
<l:VerticalLayout>
<m:RadioButton id="rb-Yes" text="Quotation" select="changeKdsr" selected="true"/>
</l:VerticalLayout>
</m:HBox>
<m:HBox alignItems="Stretch">
<l:VerticalLayout>
<m:RadioButton id="rb-No" text="material" select="changeKdsr"/>
</l:VerticalLayout>
</m:HBox>
</FlexBox>
控制器:
changeKdsr: function (e) {
var rbText = e.getSource().mProperties.text; //this returns previously selected button text
}
这个 changeKdsr 函数也被调用了两次,所以我不得不使用奇怪的逻辑来完成这项工作。
您有两个单选按钮。如果你 select 一个,两个都会改变(一个是 selected,一个是 deselected)。两个变化意味着两个事件。因此 changeKdsr
被调用了两次。
所以您可以做的是检查是否为 selected 按钮调用了事件,然后获取文本。
changeKdsr: function (oEvent) {
if (oEvent.getParameter("selected")) {
const oSource = oEvent.getSource();
const sText = oSource.getText();
}
}
我的看法:
<FlexBox
alignItems="Start"
justifyContent="SpaceBetween">
<m:HBox alignItems="Stretch">
<l:VerticalLayout>
<m:RadioButton id="rb-Yes" text="Quotation" select="changeKdsr" selected="true"/>
</l:VerticalLayout>
</m:HBox>
<m:HBox alignItems="Stretch">
<l:VerticalLayout>
<m:RadioButton id="rb-No" text="material" select="changeKdsr"/>
</l:VerticalLayout>
</m:HBox>
</FlexBox>
控制器:
changeKdsr: function (e) {
var rbText = e.getSource().mProperties.text; //this returns previously selected button text
}
这个 changeKdsr 函数也被调用了两次,所以我不得不使用奇怪的逻辑来完成这项工作。
您有两个单选按钮。如果你 select 一个,两个都会改变(一个是 selected,一个是 deselected)。两个变化意味着两个事件。因此 changeKdsr
被调用了两次。
所以您可以做的是检查是否为 selected 按钮调用了事件,然后获取文本。
changeKdsr: function (oEvent) {
if (oEvent.getParameter("selected")) {
const oSource = oEvent.getSource();
const sText = oSource.getText();
}
}