如何在详细信息页面上绑定实体对象 [英] How to bind an entity object on a Detail page

查看:53
本文介绍了如何在详细信息页面上绑定实体对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SAP UI5 开发主从 Fiori 应用程序.由于详细信息包含 40 多列,我分别为 master & 制作了单独的 OData 服务.细节.

I am developing a master detail Fiori app using SAP UI5. As the details contains more than 40 columns, I made separate OData services for master & detail.

在母版页中,数据正确传入.现在我的任务是在任何表格行上,当用户单击详细信息"时,将打开下一页,其中包含基于主表的两个关键值的详细信息.

In Master page, data are coming correctly. Now my task is that on any table line, when user clicks on Detail, next page will be open with details base on two key values of master table.

我在详细信息页面的变量中有两个键,如下所示,它工作正常:

I'm getting two keys in variables in detail page as follows and it is working fine:

var spayid = jQuery.sap.getUriParameters().get("payid");
var spaydt = jQuery.sap.getUriParameters().get("paydt");

接下来,我创建了两个过滤器,它们也工作正常.

Next, I have created two filters as follows which is also working fine.

var filter1 = new Filter({
  path: "Laufi",
  operator: FilterOperator.EQ,
  value1: spayid
});
var filter2 = new Filter({
  path: "Laufd",
  operator: FilterOperator.EQ,
  value1: spaydt
});

现在我正在调用 OData 服务,它也工作正常:

Now I am calling OData service which is also working fine:

var oODataModel = new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_pay_D_SRV?sap-client=100", {
  json: true,
  useBatch: false
});
this.getView().setModel(oODataModel);

我现在不知道如何过滤数据.上面应该包含什么,以便它根据我的过滤器 filer1filter2 过滤数据?我试过跟随,但它不起作用.

I don't know now how to filter data. What should be included in above so that it will filter data according to my filters filer1 and filter2? I have tried following but it is not working.

  filters : [ filter1, filter2 ],
  json: true,
  useBatch: false

我非常擅长 ABAP,但不是 SAPUI5 方面的专家.我正处于学习阶段.

I am very good in ABAP but not an expert in SAPUI5. I am in learning phase.

首先,我想在 OData 服务上传递参数,以便只获取所需的数据.意味着我的 OData 调用应该是这样的:

First of all, I was thinking to pass parameters on OData service so that only the required data are fetched. Means my OData call should be like this:

new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_PAYMENT_D_SRV/PdetailSet(Laufi= spayid, Laufd = spaydt)?sap-client=100");

但这似乎不太可能.

第二个选项是我将在 OData 服务中获取全部详细信息,然后在绑定到表期间我将应用过滤器.

Second option is that I will fetch whole details in OData service and then during binding to table I will apply filter.

推荐答案

sap.ui.model.Filter 类的用途通常是将过滤器应用于 UI 上的列表.例如,如果您有一个项目列表,并且希望将该列表限制为满足特定条件的项目子集.

The purpose of the sap.ui.model.Filter class is usually to apply filters to lists on the UI. For example, if you have a list of items and you want to limit that list to a subset of items which fulfills certain criteria.

但您在这里看到的似乎是一个经典的主从方案,您有一个项目列表,然后当用户选择一个项目时,会显示有关该一个项目的更多信息.

But what you have here appears to be a classic master-detail scenario where you have a list of items and then when the user selects one show more information about that one item.

这种情况的通常解决方案是将完整模型分配给详细视图,然后使用 元素绑定(也称为上下文绑定")以告诉它显示哪个项目.

The usual solution for such a scenario is to assign the full model to the detail-view and then use an element binding (also known as "context binding") on the view to tell it which item to display.

当项目的来源是点击一个已经有元素绑定的元素时,你实际上可以从点击事件中检索正确的绑定路径并将其应用到你的详细信息视图中.

When the source of the item is a click on an element which already had an element binding, then you can actually retrieve the correct binding path from the click event and just apply it to your detail-view.

来自官方演示之一:

onItemSelected: function(oEvent) {
    var oSelectedItem = oEvent.getSource();
    var oContext = oSelectedItem.getBindingContext("products");
    var sPath = oContext.getPath();
    var oProductDetailPanel = this.byId("productDetailsPanel");
    oProductDetailPanel.bindElement({ path: sPath, model: "products" });
}

当你没有任何方便的方法来获取元素路径时,那么你必须自己构建一个:

When you don't have any convenient way to get an element path from, then you have to construct one yourself:

var detailPanel = this.getView().byId("idOfDetailPanel");
detailPanel.bindElement("PdetailSet(Laufi = " + spayid +", Laufd = " + spaydt + ")");

后面的代码片段当然假设 oData 服务实际上支持使用由 laufilaufd 组成的密钥进行访问.这是由以下决定的:

The latter code snippet does of course assume that the oData-service actually supports access with a key consisting of laufi and laufd. This is decided by:

  • SAP Gateway Service Builder(事务SEGW)中实体类型关键字段的定义
  • 该 oData 服务的数据提供者类的方法 get_entity 的 ABAP 实现.
  • The definition of the key fields of the entity type in the SAP Gateway Service Builder (transaction SEGW)
  • The ABAP implementation of the method get_entity of the data provider class of that oData-service.

这篇关于如何在详细信息页面上绑定实体对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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