Hi,
I can't find the solution in the Documentation. I want to read out all Keys of a simple Combobox and want to set the first occured Key. Then trigger an external event. Here is my Code:
myFuncOnInit: function() {
this.fillComboboxViaAjaxAndSetData();
var keys = this.getView().byId("idCombobox").getItems(); // <-- always []
//var keys = this.getView().byId("idCombobox").getKeys(); // <-- always []
//var keys = this.getView().getModel("modelCombobox").getData(); //<-- Empty Object
var myKey = keys[0];
this.getView().byId("idCombobox").setSelectedKey(myKey);
this.fillTableWithAjaxAndSetData(myKey);
},
// only for show case
fillComboboxViaAjaxAndSetData: function() {
var oModelCombobox = new sap.ui.model.json.JSONModel(),
aUrl = 'http://example.com/test.xsjs'
;
this.getView().setModel(oModelCombobox, "modelCombobox");
jQuery.ajax({
url: aUrl,
method: 'GET',
dataType: 'json',
contentType: "application/json",
success: function(data) {
oModelCombobox.setData(data[0]);
}
});
},
//XML
<ComboBox id="idCombobox"
items="{modelCombobox>/}"
selectionChange="selectionChangeFunc">
<core:Item key="{modelCombobox>ID}" text="{modelCombobox>ID} {modelCombobox>Text}"/>
</ComboBox>
keys are always [], but I don't know why? There is no trouble filling the combobox or table.