Hans Bäuml
Hans Bäuml

Reputation: 229

Is there an elegant way to get JSON Data from OdataV4 Model in Openui5?

(openui5 Version 1.42)

Hello,

I have a list of items, whose data is provided by an odatav4 model (sap.ui.model.odata.v4.ODataModel)

When I select an Item, I bind it to a detail view with its own controller.

Now I would like to get the data from the odata model. This solution does not work, as the odata v4 model does not support the read method: Converting ODataModel into JSON Model

Is there a way to get the data of the selected entry as json (model or directly as data)?

What I can get is a property from the context in my controller:

this.getView().getBindingContext("ams").getProperty("Ident)

returns 1. The Identifier of my selected entry.

Upvotes: 0

Views: 3067

Answers (2)

Uwe Reeder
Uwe Reeder

Reputation: 26

You can use Context.getObject. This delivers the complete object that the context points to. However there is a bug in 1.42; the result is wrapped and you have to access it via .value[0]. This bug has been fixed in 1.44.7. See the release notes.

A solution that works in 1.42 and all following releases is to make use of the fact that getObject also can deliver parts of the object. Deliver an empty sPath parameter:

this.getView().getBindingContext("ams").getObject("")

Upvotes: 1

Rene
Rene

Reputation: 331

If you call the method getObject on the binding context you should get the entity as json.

this.getView().getBindingContext("ams").getObject()

Upvotes: 3

Related Questions