SAP OData 的 V2 模型
发布日期:2021-06-30 14:48:56 浏览次数:2 分类:技术文章

本文共 2104 字,大约阅读时间需要 7 分钟。

文档地址:

https://sapui5.hana.ondemand.com/#/topic/6c47b2b39db9404582994070ec3d57a2#loio66a130fa4d10411b8fc90df00185554b

The OData model is a server-side model, meaning that the data set is only available on the server and the client only knows the currently visible (requested) data. Operations, such as sorting and filtering, are done on the server. The client sends a request to the server and shows the returned data.

OData 模型是一个服务器端模型,这意味着业务数据只在服务器端可用,客户端只维护了其当前发出请求后,服务器端返回的部分数据。围绕数据进行的排序和过滤等操作,都是先在服务器端执行,再将执行结果返回给客户端。

Requests to the back end are triggered by list bindings (ODataListBinding), context bindings (ODataContextBinding), and CRUD functions provided by the ODataModel. Property bindings (ODataPropertyBindings) do not trigger requests.

目前 OData 模型通过如下 API 触发向后台的数据请求:

  • List binding - ODataListBinding
  • context binding - ODataContextBinding
  • 增删改查操作

The following two versions of the OData model are implemented:

  • sap.ui.model.odata.ODataModel
  • sap.ui.model.odata.v2.ODataModel.

The v2.ODataModel has an improved feature set and new features will only be implemented in this model.

sap.ui.model.odata.ODataModel is deprecated. We recommend to only use v2.ODataModel.

前者已经被标注成 deprecated 状态,后者是 SAP 推荐使用的数据模型。

注意:OData V2 模型已经支持客户端的排序和过滤了。

在这里插入图片描述

OData model 模型实例的创建方法:

var oModel = new ODataModel("http://services.odata.org/Northwind/Northwind.svc/");var oModel = new ODataModel({
serviceUrl: "http://services.odata.org/Northwind/Northwind.svc"});

当模型实例创建时,自动触发获取 OData 服务元数据的请求:

http://services.odata.org/Northwind/Northwind.svc/$metadata

Only the first model instance triggers a $metadata request. A JSON representation of the service metadata can be accessed by calling the getServiceMetadata() method on an OData model instance.

JSON 格式的服务元数据,通过模型实例的 getServiceMetadata 方法返回。

var oMetadata = oModel.getServiceMetadata();

In the v2.ODataModel, the service metadata is loaded asynchronously. It is not possible to load it synchronously. To get notified when the loading is finished, attach the metadataLoaded event.

对于 2.0 版本的 OData 模型来说,服务元数据采取一部方式加载,如果在应用程序里想捕捉元数据加载成功的事件,需要监听 metadataLoaded 事件。

转载地址:https://jerry.blog.csdn.net/article/details/117434467 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:如何处理使用 SAP UI5 消费真实的 OData 服务时遇到的跨域问题
下一篇:Adding Applications for JavaScript Storefronts in SAP 电商云

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年05月02日 08时59分05秒