Reputation: 4418
I am facing issue while setting the default value in dropdown box in SAPUI5.
Currently I am using below code :
fields : [ new sap.ui.commons.DropdownBox("Cities", {
selectedKey: "City3",
items : [ new sap.ui.core.ListItem("City1", {
text : "DE (Germany)"
}), new sap.ui.core.ListItem("City2", {
text : "GB (United Kingdom)"
}), new sap.ui.core.ListItem("City3", {
text : "IN (India)"
}), new sap.ui.core.ListItem("City4", {
text : "US (United States)"
}) ]
})
}) ]
But In List box always it shows DE (Germany)
value but I want to default set other value.
How to do that?
Upvotes: 2
Views: 16360
Reputation: 160
It will be helpful if you use key
and name
sap.ui.getCore().byId('Cities').setSelectedItemId('YOUR ITEM ID')
//if you are using key value pair then its as easy as
sap.ui.getCore().byId('Cities').setSelected('YOUR ITEM ID').setSelectedKey('YOUR KEY VALUE(1/2/3..)')
Upvotes: 1