如何利用导航属性? [英] How to make use of navigation property?

查看:94
本文介绍了如何利用导航属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OData服务(V2)包含以下多个导航属性:

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: {…}}

如上所示,to_IClassHeaderVhto_IClassVh是导航属性.
请求OData服务的代码:

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
});

如何通过代码从导航属性中获取URL?我可以通过以下对象获取它:

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.

推荐答案

导航属性是可以导航到相关实体类型的属性(

Navigation properties are, as the name suggests, properties with which you can navigate to related entity types (spec). 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 EDM[1] for example:

客户
导航:订单"
1 ___ n 订购
导航:客户"

Customer
Nav: "Orders"
1 ___ n Order
Nav: "Customer"

...来自此 Northwind服务(元数据)

一个导航实体到集合 :

<Page binding="{/Customers('ALFKI')}">
  <List items="{Orders}">
    <StandardListItem title="{OrderID}" />
  </List>
</Page>

一个实体导航另一个单个实体 :

<Page binding="{/Orders(10643)}">
  <Panel binding="{Customer}" headerText="{ContactName}" />
</Page>

以下是使用导航属性的示例: https://embed .plnkr.co/F3t6gI8TPUZwCOnA

Here is an example using navigation properties: https://embed.plnkr.co/F3t6gI8TPUZwCOnA

在您的情况下,您可以使用to_IClassHeaderVhto_IClassVh代替CustomerOrders.然后,UI5将相应地为您发送请求.请记住,只有上下文绑定和聚合绑定才能处理发送请求.绑定属性.

In your case, you'd use either to_IClassHeaderVh or to_IClassVh in place of Customer or Orders. UI5 will then send requests for you accordingly. Keep in mind that only context- and aggregation-bindings handle sending requests. Property-binding does not.

如果您想知道XML中的binding属性;这只是绑定单个实体(上下文)的方法之一.如果通常需要动态指定实体键(ID),则必须使用API​​ bindElement

In case you're wondering about the binding attribute in XML; it's just one of the ways to bind a single entity (context). If you need to specify entity keys (IDs) dynamically, which is usually the case, you'll have to use the API bindElement[API] in JS instead. I'm hardcoding the keys here just for the sake of the examples.

此外,您还可以添加

Additionally, you can also add the binding parameter expand which awaits navigation property name(s).

<Page binding="{
  path: '/Orders(10643)',
  parameters: {
    expand: 'Customer'
  }
}" >
  <!-- ... -->
</Page>

响应::以下是使用扩展的示例: https: //embed.plnkr.co/wAlrHB

Here is an example making use of expand: https://embed.plnkr.co/wAlrHB

[1]:实体数据模型"-特定于OData的E/R模型

[1]: "Entity Data Model" - OData specific E/R model

这篇关于如何利用导航属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆