Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly bind two data properties into one control property using OData model?

I am using an OData model to bind UI controls to GW services. In the service metadata, there are, say, "FirstName" and "LastName" in the data structure. On the UI, say, I am using a Label control.

Now the question is how to bind the Text property of Label to a string of "FullName" (which is "FirstName"+"LastName") using OData Model directly? If I use the JSON model, I can create a local variable, FullName = FirstName + LastName, and bind the Text property to FullName. But how could I do this using OData Model?

like image 754
Dr. Dong Zhu Avatar asked Mar 11 '14 08:03

Dr. Dong Zhu


People also ask

Is two way binding for aggregation in v2 OData model implemented?

The v2. ODataModel enables two-way binding. Per default, all changes are collected in a batch group called "changes" which is set to deferred.

What is one way and two way binding in SAPUI5?

There three binding modes in SAPUI5: One way binding – Data flows from model to control. Change in the model data updates all the corresponding bindings. Two way binding – Data flows from model to view and view to model. Change in the control results in the change in application data.

What is OData model?

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.


2 Answers

Additionally, you can enable complex data binding in sap-ui-core.js:

<script src="resources/sap-ui-core.js"
        id="sap-ui-bootstrap"
        data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3"
        data-sap-ui-xx-bindingSyntax="complex"></script>

And then use both properties:

var oLabel = new sap.ui.commons.Label({
        text : "{firstName} {lastName}"
});
like image 67
Nikolay Nadorichev Avatar answered Sep 18 '22 08:09

Nikolay Nadorichev


You could use calculated fields for data binding, for instance:

var oLabel = new sap.ui.commons.Label()
.bindProperty("text", {
  parts: [
    {path: "/firstName", type: new sap.ui.model.type.String()},
    {path: "/lastName", type: new sap.ui.model.type.String()}
  ],
  formatter: function(firstName, lastName){
    return firstName + " " + lastName;
  }
});
like image 40
Qualiture Avatar answered Sep 19 '22 08:09

Qualiture