Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

odata - How to make use of navigation property?

An OData service (V2) contains multiple navigation properties as following:

ClassNum: "ZPM_TEST_01"
ClassNumDescr: "ZPM_TEST_01"
ClassType: "001"
InternalClass: "0000000130"
ValidFrom: Tue Sep 04 2018 02:00:00 GMT+0200 (Central European Summer Time) {}
ValidUntil: Fri Dec 31 9999 01:00:00 GMT+0100 (Central European Standard Time) {}
to_IClassHeaderVh: {__deferred: {…}}
to_IClassVh: {__deferred: {…}}

As you can see above, to_IClassHeaderVh and to_IClassVh are navigation property.
The code, that requested the OData service:

oModel.read(sUri, {
  success: function (oData) {
  },
  error: Util.showErrorClassNotFound
});

How can I get the URL from navigation property via code? I could get it via the object as following:

oData.to_IClassVh.__deferred.uri 

But I do not know if it is the right way or not.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Navigation properties are, as the name suggests, properties with which you can navigate to related entity types. The UI5 framework supports this feature too so that app developers don't have to extract URLs by hand. In fact, you won't even need to call read. Let's take this entity data model for example:

CustomerSet
NavigationProperty: "ToOrders"
1 ___ n OrderSet
NavigationProperty: "ToCustomer"

Navigating from one entity to a collection of entities:

<Page><!-- bound to /CustomerSet('ALFKI') -->
  <List items="{ToOrders}">
    <StandardListItem title="{OrderID}" />
  </List>
</Page>

Navigating from one entity to another one entity:

<Page><!-- bound to /OrderSet(10643) -->
  <Panel binding="{ToCustomer}" headerText="{CustomerName}" />
</Page>

The ODataContextBinding and ODataListBinding will then send requests for you automatically.


The binding in XML code above is one of the ways to bind a single entity.
See also the documentation topic Context Binding (Element Binding).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...