Reputation: 2030
I only find setSelectedItem
setSelectedItemId
setSelectedKey
in sap.m.select doc, how to setSelected text in sap.m.select
?
For example:
<Select
forceSelection="false"
selectedKey="{/ProductCollection/0/ProductId}"
items="{
path: '/ProductCollection',
sorter: { path: 'Name' }
}">
<core:Item key="{ProductId}" text="{Name}" />
</Select>`
How to get selected text (Name) in this control ?
Upvotes: 1
Views: 12042
Reputation: 3948
The keys shall be unique but the texts do not have to be unique. In some situations the texts are translated but the keys stay the same. Thats why the keys are used for selection.
To get the text of the selected item you can use
var text = select.getSelectedItem().getText();
To select an item by text you have to search the model for the item, get its key and use that with setSelectedKey()
.
Upvotes: 2