文档地址:
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"});
1
2
当模型实例创建时,自动触发获取 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();
1
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 事件。