Hello UI5 people,
Please help me with this. I am trying to change the content of a comboBox on "change" event of another comboBox.
Below is my code snippet, kindly let me know where i am going wrong. The content of JSON model is not being changed. How to achieve this.
Code:
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
hardware:[
{device:"PC"},
{device:"Monitor"},
{device:"Keyboard"},
{device:"Mouse"},
{device:"Speaker"},
{device:"Printer"}],
});
sap.ui.getCore().setModel(oModel);
var oModel1 = new sap.ui.model.json.JSONModel();
oModel1.setData({
hardware:[
{device1:"Phone"},
{device1:"Computer"},
{device1:"Television"},
{device1:"Aeroplane"},
{device1:"Ship"},
{device1:"Pen"}],
});
sap.ui.getCore().setModel(oModel1);
new sap.ui.commons.Label({
text:"Issue sub Category:"
}).placeAt("content");
var comboBox2 = new sap.ui.commons.ComboBox({
id : "cmb2", // sap.ui.core.ID
}).placeAt("content");
new sap.ui.commons.Label({
text:"Issue main type:"
}).placeAt("content");
new sap.ui.commons.ComboBox({
id : "cmb1", // sap.ui.core.ID
//value : '', // string
//name : undefined, // string
//selectedKey : undefined, // string
//selectedItemId : undefined, // string
items : [ new sap.ui.core.ListItem({
id : "item1", // sap.ui.core.ID
text : "Accounts", // string
enabled : true, // boolean
//key : undefined, // string
key : "Accounts", // string
}),
new sap.ui.core.ListItem({
id : "item2", // sap.ui.core.ID
text : "Gowdown Servicing", // string
enabled : true, // boolean
key : "Gowdown Servicing", // string
}),
new sap.ui.core.ListItem({
id : "item3", // sap.ui.core.ID
text : "Communication", // string
enabled : true, // boolean
key : "Communication", // string
})
], // sap.ui.core.ListItem
//listBox : undefined, // sap.ui.commons.ListBox
change : function(oEvent) {
var selectedItem = oEvent.getParameter("selectedItem");
console.log(selectedItem);
var key1 = oEvent.oSource.getSelectedKey();
console.log(key1);
if ( key1 = "Accounts")
{
comboBox2.setModel(oModel);
var oItemTemplate1 = new sap.ui.core.ListItem();
oItemTemplate1.bindProperty("text", "device");
oItemTemplate1.bindProperty("enabled", "enabled");
comboBox2.bindItems("/hardware", oItemTemplate1);
}
else if (key1 = "Gowdown Servicing")
{
comboBox2.setModel(oModel1);
var oItemTemplate1 = new sap.ui.core.ListItem();
oItemTemplate1.bindProperty("text", "device1");
oItemTemplate1.bindProperty("enabled", "enabled");
comboBox2.bindItems("/hardware", oItemTemplate1);
}
},
}).placeAt("content");
Best Regards,
Chetna