Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

binding of text field vs setvalue of text field from model

Hi ,

I have a json model having an array of records. In my ui5 layout i just have a set of text fields for each of the fields defined in the json model. I figured out that there are two ways by which i can read the particular index of the json array from model and bring it to the text field.

1) Using binding

var oJson = new sap.ui.model.json.JSONModel();

   oJson.loadData("Data/empdata.json","",false);

   sap.ui.getCore().setModel(oJson);

   oTF_Empno.bindValue("/Empl_Data/"+emp_index+"/Empno");

2) Using setValue instead of binding

var oJson = new sap.ui.model.json.JSONModel();

   oJson.loadData("Data/empdata.json","",false);

   sap.ui.getCore().setModel(oJson);

   sap.ui.getCore().byId("Empno").setValue(sap.ui.getCore().getModel().getData().Empl_Data[emp_index].Empno);

Both the methods are working but I am confused regarding the difference and usefulness of them. Also from performance point of view , which of the above methods is advisible to use for different scenarios

Regards

Amber

replied

HI Amber

Among other things, the main advantage is to simplify code development and maintenance. Once the controls are bind to the property in the model, we no longer need to hunt down the control by its ID and setValue or reset Value.

JS Bin - Collaborative JavaScript Debugging

This is new sample, we can use binding to control the visibility of icon and have one than one control having the same values.

When we reset the value in the model, all the corresponding values in the controls changes all together.

Thanks

-D

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question