on 06-14-2016 3:26 PM
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") ;
Resolved the issue by changing
oComboBox = sap.ui.getCore().byId("cmb1"); to
oComboBox = this.getView().byId("cmb1");
But both should work as per my understanding. what is the difference here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oComboBox.setModel(xmodel);
this.getView().byId("cmb1").setBindingContext("/xmodel/items/0") ; //no need
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Justin,
If you already set a core model with sap.ui.getCore().setModel(). Did your try saving the combobox items in the property of Global Model? Something like:
var oModel = sap.ui.getCore().getModel();
oModel.setProperty("/oComboBoxItems", mData);
And in the XML view you can give the above binding path for 'items' aggregation. Here is a sample: Plunker (Where I am using single model with different path for table and combobox)
(or)
an alternative would be using named models.
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.