简体   繁体   中英

Segmented Button OpenUI5 setSelectedButton

I am trying to use the function setSelectedButton() from SegmentedButton, but i am not able to change the 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"); the SegmentedButton Element stops selecting any of the Items.

Check this 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). 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

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...

The easiest way to is to use the new UI5 chrome inspector and select your button to see the whole ID of the buttons. Then in your code make sure your building the ID's with proper pre-pended aggregation ID's.

Derek

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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