头图

The SAP OData V4 model supports the following three types of data binding:

  1. List bindings, which represent bindings of collection types, such as /SalesOrderList , the type of binding instance is sap.ui.model.odata.v4.ODataListBinding .
  2. Context binding, based on a single entity, such as /SalesOrderList('0500000000') , the type of binding instance is sap.ui.model.odata.v4.ODataContextBinding .
  3. Property bindings, representing properties in an entity or complex type, such as /ProductList('HT-1000')/Name . The type of the binding instance is sap.ui.model.odata.v4.ODataPropertyBinding .

Although the OData V4 model itself provides some APIs, namely factory methods bindList, bindContext and bindProperty to create binding instances, usually, application developers will never call these methods directly , but create a binding instance in the following way.

Using the bindElement method of SAP UI5 controls

example:

 oForm.bindElement("{/SalesOrderList('0500000000')}");

This example binds the form control to a specified Sales order instance, so all elements contained in the form display the instance data of the sales order in a relative binding manner.

In actual project applications, binding expressions can be more complex:

 oForm.bindElement({path : "/SalesOrderList('0500000000')", parameters : {$expand : "SO_2_SOITEM", ...}, events : {dataReceived : '.onDataEvents', ...}});

The above shows how to monitor the event dataReceived and respond to it in the event handler defined by yourself onDataEvents .

Binding declaration in XML view

code show as below:

 <Table items="{path : '/SalesOrderList', parameters : { $expand : 'SO_2_BP', $filter : 'BuyerName ge \'M\'', ...}, events : {dataReceived : '.onDataEvents', ... } }">

The above code binds the items property of the Table control to the OData collection /SalesOrderList . The accompanying parameter is also specified: $expand , which is the standard syntax of OData.

For a detailed description of the binding path of OData V4, you can check its official website .

If the leading slash symbol / is added, each resource path (relative to the service root URL, and without the query option) is a valid data binding path in this model.

For example, an entity instance with key A/B&C can be accessed using /EMPLOYEES('A%2FB%26C') . Note that proper URI encoding is required.

If the binding's path begins with a forward slash / , the bindings are called absolute bindings; otherwise they are called relative bindings. The initial meaning of relative bindings is that as long as they don't have a binding context, they have no data to display.


注销
1k 声望1.6k 粉丝

invalid