0
votes

In the demo kit of openui5, the section Element Binding involves two forms of data binding implementation.

As in the code below:

var oMatrixLayout = new sap.ui.commons.layout.MatrixLayout();
oMatrixLayout.bindElement("/company");
oMatrixLayout.createRow(
	new sap.ui.commons.Label({text: "Name:"}),
	new sap.ui.commons.TextField({value: "{name}"})
);

oMatrixLayout.createRow(
	new sap.ui.commons.Label({text: "Revenue:"}),
	new sap.ui.commons.TextField({value: "{revenue}"})
);
oMatrixLayout.createRow(
	new sap.ui.commons.Label({text: "Employees:"}),
	new sap.ui.commons.TextField({value: "{employees}"})
);

When specifying the values for text fields, we use curly brackets({}) to indicate the value is from the model. However, in the code that immediately follows this one, no curly brackets are used:

var data = {clients:[{firstName:"Donald", lastName:"Duck"}]};
...// create and set model here
var oLabel = new sap.ui.commons.Label("myLabel");
oLabel.bindProperty("text", "firstName");
oLabel.bindElement("/clients/0");

As you can see, no curly brackets are used in oLabel.bindProperty("text", "firstName");
So, what's the difference between the two examples? When to use curly brackets in data binding and when not?

1

1 Answers

1
votes

When to use brackets?

While defining the controls along with the property use brackets: (binding at RUNTIME)

Example: new sap.ui.commons.TextField({value: "{name}"})

and in terms of XML <Label text="{name}"/>

When not to use brackets? // binding at a later time

whenever you're using bindProperty method.

Read more about property binding here