cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined when trying to get selectedKey from sap.m.Select

csimpson
Explorer
0 Kudos

I am trying to get data from sap.m.Select but it is always undefined and I am not sure what the issue is.

this.tierTemplate = new sap.ui.core.Item("tierLevel", {key: "{Level}" ,text: "{Level}"});
		var tierOption = new sap.m.Select("tierOption", {
			enabled: true,
			items: {
				path: "/level",      
				template: this.tierTemplate
			},
			
			width: "200px"
		});
onPressSave: function(){
		//var tier = sap.ui.getCore().byId("tierLevel").getSelectedItem();
		var tier = this.getView().byId("tierLevel").getSelectedKey().getTex();
		console.log(tier);
		},


Accepted Solutions (1)

Accepted Solutions (1)

vamsixk
Active Participant

you have defined a template upon which the items in the sap.m.select are to be populated.

you have assigned the id "tierleve"l to template.

when you say byID(tierlevel) you are fetching the sap.ui.core.item object. but selectedKey method is defined for sap.m.select and not for sap.ui.core.item.

so fetch the object for sap.m.select and then use getselectedkey.

Kind Regards,

Vamsi

Answers (2)

Answers (2)

csimpson
Explorer
0 Kudos

Thanks guy. I got it working with you-all's help!

developerone
Contributor
0 Kudos

Your select is tierOption and you are trying to read from tierLevel if I'm not mistaken.