Skip to Content

Error: Uncaught TypeError: Cannot read property 'setModel' of undefined

Hi Experts,

I am getting Error: "Uncaught TypeError: Cannot read property 'setModel' of undefined" while trying to bind a combobox

can anyone help me find out what I might be doing wrong?

Controller part:

var combmodel = {
	"comment": "List of IDs",
	"results" : [
		{
		"Key": "1",
		"id" : "AP1",
		"Temp" : "SIRI"
		},
		{
		"Key": "2",
		"id" : "AP2",
		"Temp" : "ALEXA"
		}
	]
};
var aoModel = new sap.ui.model.json.JSONModel(combmodel);
this.byId("ComboBox").setModel(aoModel).setPlaceholder("Choose ID");

View part:

<layout:VerticalLayout >
	<ComboBox id="ComboBox" showSecondaryValues="true"
	items="{
		path: '/results'
	}" selectionChange="idSelect">
	<core:ListItem key='{Key}' text='{id}'
		additionalText='{Temp}' />
	</ComboBox>
</layout:VerticalLayout>

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 23 at 10:08 AM

    Hi Armoghan,

    Please try below code,

    var oModel = new sap.ui.model.json.JSONModel({ data: combmodel });

    this.getView().byId("ComboBox").setModel(oModel);

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21 at 04:41 AM
    try this.getView().byId("ComboBox")

    what's the version of your ui5?

    Add comment
    10|10000 characters needed characters exceeded