Skip to Content
0

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

Mar 21 at 04:24 AM

30

avatar image

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>

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Prachi C Mar 23 at 10:08 AM
0

Hi Armoghan,

Please try below code,

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

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

Thanks

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Mar 21 at 04:41 AM
0
try this.getView().byId("ComboBox")

what's the version of your ui5?

Share
10 |10000 characters needed characters left characters exceeded