Reputation: 141
<MultiComboBox id="empDropDown" items="{/emp}"
selectedKeys="{/emp/0/empNumber}">
<core:Item key="{empNumber}" text="{Name}" />
</MultiComboBox>
The data is directly bound to data in the model in the following format: { "empNumber": 8683, "Name": "A001", "Description": "Description 1", }
Upvotes: 0
Views: 3913
Reputation: 1754
As I did not understood exactly what you want to get I did simple example in the xml:
<MultiComboBox id="comboBoxTest" selectedKeys="key0,key1" width="150px">
<core:Item id="idName1" text="A000" key="key0" />
<core:Item id="idName2" text="A001" key="key1" />
<core:Item id="idName3" text="A002" key="key2" />
<core:Item id="idName4" text="A003" key="key3" />
</MultiComboBox>
And also I did similar working example for the controller in the jsbin as different approach.
var mData = {
items:[
{key:"0",name:"A000"},
{key:"1",name:"A001"},
{key:"2",name:"A002"},
{key:"3",name:"A003"}
]
};
var oModel = new sap.ui.model.json.JSONModel(mData); //set data here
sap.ui.getCore().setModel(oModel, "ComboBoxData");
var oItemTemplate = new sap.ui.core.Item({
key : "{key}",
text : "{name}"
});
var mcb = new sap.m.MultiComboBox({
id : "mcb",
items : {
path : "/items",
template : oItemTemplate,
}
});
mcb.setModel(oModel);
//here you can select pre chosen values, for example [0,1] first two names are chosen
mcb.setSelectedKeys([0,1]);
mcb.placeAt('content');
Upvotes: 2