简体   繁体   English

分段按钮OpenUI5 setSelectedButton

[英]Segmented Button OpenUI5 setSelectedButton

I am trying to use the function setSelectedButton() from SegmentedButton, but i am not able to change the Button. 我正在尝试使用来自SegmentedButton的函数setSelectedButton() 但是我无法更改Button。
For Example: 例如:

var navCheck = new sap.m.SegmentedButton({
    items: [
        new sap.m.SegmentedButtonItem("Off", {text: "Navigation Off"}), 
        new sap.m.SegmentedButtonItem("On", {text: "Navigation On"})
    ],
    select: function () {
    }
});

When I am using setSelectedButton("On"); 当我使用setSelectedButton("On"); the SegmentedButton Element stops selecting any of the Items. SegmentedButton元素停止选择任何项目。

Check this JSBin . 检查此JSBin

From what I have learned so far, sap.m.SegmentedButtonItem control has property oButton which holds actual id of the button (your ids "on" and "Off" get the "parent" control, not the button itself). 根据到目前为止的经验, sap.m.SegmentedButtonItem控件具有属性oButton ,该属性保存按钮的实际ID(您的ID为“ on”和“ Off”是“父”控件,而不是按钮本身)。 Here how I solved the problem: 这是我如何解决问题的方法:

doSomething: function() {
    var test = sap.ui.getCore().byId("Test");
    var oButton = sap.ui.getCore().byId("On");
    test.setSelectedButton(oButton.oButton.getId());
}

Here is JSBIN example: LINK 这是JSBIN示例: LINK

If somebody has a better solution, I'd gladly take a look at it. 如果有人有更好的解决方案,我会很乐意看一下。

You can use the setSelectedButton passing in the ID but you need to verify you are using the full ID including any parent aggregation ID's... 您可以使用传入ID的setSelectedButton,但需要验证您使用的是完整ID,包括所有父聚合ID的...

The easiest way to is to use the new UI5 chrome inspector and select your button to see the whole ID of the buttons. 最简单的方法是使用新的UI5 chrome检查器,然后选择按钮以查看按钮的整个ID。 Then in your code make sure your building the ID's with proper pre-pended aggregation ID's. 然后,在代码中,确保使用正确的前置聚合ID来构建ID。

Derek 德里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM