I created a mockserver for testing purpose on my sapui5 app.
The definition of the dataSources
structure in the manifest.json
file looks as following:
"dataSources": {
"NorthwindService": {
"uri": "/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
}
and the model definition:
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "ch.app.northwind.i18n.i18n"
}
},
"northwind": {
"uri": "",
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay",
"defaultCountMode": "Request"
},
"dataSource": "NorthwindService",
"preload": true
}
},
calling the model controller:
this.getView().getModel("northwind")
.read("/Customers/$count", {
success: function(oData) {
jQuery.sap.log.info(oData);
},
error: function(oError) {
jQuery.sap.log.info(oError);
}
});
It complains:
Overview.controller.js?eval:29 Uncaught (in promise) TypeError: Cannot read property 'read' of undefined
at f.queryTotalCustomers (Overview.controller.js?eval:29)
at f.onInit (Overview.controller.js?eval:12)
at f.a.fireEvent (EventProvider-dbg.js:228)
at f.a.fireEvent (Element-dbg.js:431)
at f.fireAfterInit (ManagedObjectMetadata-dbg.js:568)
at r (Component-dbg.js:162)
at f.h.runAsOwner (Component-dbg.js:549)
at P (View-dbg.js:429)
at eval (View-dbg.js:467)
What am I doing wrong?