Reputation: 197
I have an application that works for test purposes with local JSON mock data. The oData Object contains arrays with values and the application works as desired. Now we are switching from the local mock data File to data consumption with an oData service from a SAP backend system. Here I get the data in JSON Objects and not all the functionality works as desired (example filter functions).
Can somebody share some thoughts about JSON Objects and Arrays with me? And how can I get the data from the backend system in an array instead of an object?
In the mock data version I do this to define my model:
this._oModel = new JSONModel(jQuery.sap.getModulePath("myApplication", "/localService/mockdata/nodesSet.json"));
In the oData Version the model is defined in manifest.json:
this._oModel = this.getOwnerComponent().getModel();
Note: I am aware of the different names of the entities (example: nodes vs nodesSet) and this is not part of the problem.
Thanks!
Upvotes: 0
Views: 419
Reputation: 1098
One simple way would be not to create the model in the Manifest and do an explicit read in the controller as:
var oModel = new sap.ui.model.odata.v2.ODataModel(url, true);
that=this;
oModel.read( "/Products", {
urlParameters: {
"$skip": 0,
"$top": 50
},
success: function( oData) {
//here oData shall have an array of objects "results"
**-------------Set the model here using this array -> results ------**
},
error: function(oError) {
alert("error");
}
});
I am however not proud of this solution and will check if I can comment better.
Upvotes: 0