Skip to Content
0
Jun 14, 2016 at 02:26 PM

combo box binding inside controller

1096 Views

Hi

I am using XML views and want to bind a combo box control to a json model defined in init method.

I dont want to use sap.ui.getCore().setModel() since it breaks another binding in my case. I am looking to bind combo box only with this model.

My code is as below:

<ComboBox id ="cmb1"

items="{

path: '/items',

sorter: { path: 'key' }

}">

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

</ComboBox>

var mData = {

// "selected":["0","1"],

items:[

{key:"0",text:"Display"},

{key:"1",text:"Edit"}

]

};

var xmodel = new sap.ui.model.json.JSONModel(mData);

oComboBox = sap.ui.getCore().byId("cmb1");

//oComboBox.bindElement("/xmodel/items"); //does not work.

this.getView().byId("cmb1").setBindingContext("/xmodel/items/0") ;