cancel
Showing results for 
Search instead for 
Did you mean: 

Create simple SAP UI5 ComboBox

0 Kudos
1,053

I have a simple model that I want to bind to a sap.m.ComboBox. The data look like this:

(2) ["Tabelle1", "Tabelle2"]
0: "Tabelle1"
1: "Tabelle2"

What I do is this:

... some unimportant stuff before...    
var sheets = new sap.ui.model.json.JSONModel(sheetNames);
var comboBox = that.getView().byId("selectSheet");
comboBox.setModel(sheets);
var oItemTemplate = new sap.ui.core.Item();
comboBox.bindItems("/sheets", oItemTemplate)

the comboBox gets created in my XML view:

<m:ComboBoxid="selectSheet"items="{path: '/sheets'}"change="onSheetSelected"><core:Item/></m:ComboBox>

After setting the Model or binding the Items nothing happens.. I feel like that's some simple coding that I'm doing wrong here. Please advise me how to do this. The ComboBox should end up with two simple choices "Tabelle1" and "Tabelle2".

View Entire Topic
maheshpalavalli
Active Contributor
0 Kudos

Your template is incorrect. You need to pass the properties as well and with binding and you dont need to set the binditems in javascript code manually as you are setting it already in XML view.

	<core:Item key="{key}" text="{text}" /><br>
0 Kudos

Well I don'T have any "key" or "text" in my Model as you can see..

maheshpalavalli
Active Contributor
0 Kudos

So you now have to first get the data and manipulate it and create name value pairs and bind them accordingly because as far as I know SAP won't generate combo box items just from array, it needs to have key value pair