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?
The v2. ODataModel enables two-way binding. Per default, all changes are collected in a batch group called "changes" which is set to deferred.
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.
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.
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}"
});
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;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With