Reputation: 117
I have this code given below in view page:
<Select id="deptId" required="true">
<core:Item key="1" text="Agri" />
<core:Item key="2" text="Trade" />
<core:Item key="3" text="Marketing" />
</Select>
I need to get value in Controller page. I added this code below:
department = this.getView().byId("deptId").getSelectedKey();
But all I am getting is key value like 1
, 2
, and 3
and not "Agri"
, "trade"
and "Marketing"
.
I even tried adding .getSelectedKey().getValue()
which is throwing an error.
Please help me to fix this.
Upvotes: 0
Views: 1564
Reputation: 2645
Based on the documentation of sap.m.Select you should go with getSelectedItem()
instead of getSelectedKey()
.
Upvotes: 0
Reputation: 3994
You simply have to get the selected Item control and get the text from that control.
var oItem = this.getView().byId("deptId").getSelectedItem();
var department = oItem.getText();
Upvotes: 1