如何从 OData 服务的导航属性中获取数据 [英] How to Get the Data from Navigation Property of OData Service

查看:96
本文介绍了如何从 OData 服务的导航属性中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建 Master Details UI5 应用.我正在调用 OData 服务并能够显示来自主列表中实体集的数据.在详细信息部分,我们正在创建一个表单,我想显示来自导航实体集的数据.我开始知道我们不能在一次调用中调用导航实体集,怎么做?

We are creating the Master Details UI5 app. I am calling the OData service and able to display the data from an entity set in Master list. On detail section, we are creating a form and I want to display the data which is coming from Navigation entity set. As I came to know that we can not call navigation entity set in a single call, how can it be done?

<EntityType Name="Product" sap:content-version="1">
    <Key>
        <PropertyRef Name="ProductID"/>
    </Key>
    <Property Name="ProductID" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Product ID" sap:updatable="false"/>
    <Property Name="TypeCode" Type="Edm.String" Nullable="false" MaxLength="2" sap:label="Type Code"/>
    <NavigationProperty Name="ToSalesOrderLineItems" Relationship="GWSAMPLE_BASIC.Assoc_Product_SalesOrderLineItems" FromRole="FromRole_Assoc_Product_SalesOrderLineItems" ToRole="ToRole_Assoc_Product_SalesOrderLineItems"/>
    <NavigationProperty Name="ToSupplier" Relationship="GWSAMPLE_BASIC.Assoc_BusinessPartner_Products" FromRole="ToRole_Assoc_BusinessPartner_Products" ToRole="FromRole_Assoc_BusinessPartner_Products"/>
</EntityType> 

我想展示ToSupplier的数据.

推荐答案

嗯,实际上你可以在一个请求中得到它.

Well, you can get it in a single request actually.

假设您的BusinessPartner"实体有一个名称字段,并且您想要显示如下内容:

Lets say that your "BusinessPartner" entity has a name field and you want to display something like this:

<Panel>
   <Text id="txtProductID" text="Product ID Comes Here"/>
   <Text id="txtSupplierName" text="Supplier BP Name Comes Here"/>
</Panel>

您可以做的是使用常规绑定语法(使用相对绑定),因为它通常在详细信息视图中完成:

What you can do, is to use regular binding syntax (with relative bindings), as it is usually done in details views:

<Panel>
   <Text id="txtProductID" text="{ProductID}"/>
   <Text id="txtSupplierName" text="{ToSupplier/Name}"/>
</Panel>

如果您直接尝试此操作,则供应商名称"文本控件中将看不到任何内容.这是因为,默认情况下,您不会请求 ToSupplier 导航被扩展(请查看 OData 规范).

If you would try this directly, you would not get anything in the "Supplier Name" text control. This is because, by default you are not requesting the ToSupplier navigation to be expanded (check out chapter 4.6 from the OData Spec).

您应该在调用 bindElement(在默认模板中,这是在细节控制器的一个名为 _bindView 的方法中完成的).展开可以作为参数传递给 绑定 本身像这样:

You should do this where you are calling bindElement on the detail view (in the default template, this is done in a method called _bindView of the detail controller). The expand can be passed as a parameter to the binding itself like so:

oView.bindElement({
    path: sMyPathToAProduct,
    parameters: {
        expand: "ToSupplier"
    }
});

您可以根据需要扩展任意数量的导航和任意深度(您可以在该参数中将导航作为逗号分隔的列表传递).这里唯一的限制是您的后端应该支持扩展/可能对扩展的深度有一些限制.

You can expand as many navigations as you like and as deep as you like (you can pass the navigations as a comma separated list in that parameter). The only constraint here is that your backend should support expands / might have some limitations on how deep you can go with expands.

这篇关于如何从 OData 服务的导航属性中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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