cancel
Showing results for 
Search instead for 
Did you mean: 

Put constant inside binding

Former Member
0 Kudos

Hi,

There is a way inside binding to put some constant

instead of

  new sap.ui.commons.TextView({
  text: "{FILENAME}",

  new sap.ui.commons.TextView({
  text: constant "{FILENAME}",

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Stephane,

Yes you can, you have to do -


  new sap.ui.commons.TextView({

  text: constant + "{FILENAME}"              //constant Value should be declared in a variable

  })

Please check the sample here - JS Bin - TextView Binding


In my code, I have done like this -



var oTextView = new sap.ui.commons.TextView({text: "Customer - " + "{/modelData/employeesData/0/Name}"});

Regards,

Sai Vellanki.

former_member182862
Active Contributor
0 Kudos

IMO, Sai's solution is good.

However, we have to be careful if the text is localized. Then it is better not to do string concatenation but have a sap.ui.model.resource.ResourceModel to defined the format.

then you can do

var oTextView = new sap.ui.commons.TextView({
    text: {
       parts: ['i18n>localizedStr', 'FILENAME'],
       formatter: function(localizedString, filename) {
           return localizedString.replace('{0}', filename);
       }
    }
});

Where i18n is the resource model and example of localizedStr is

constant {0}

Thanks

-D

saivellanki
Active Contributor
0 Kudos

Nicely done Dennis

Regards,

Sai Vellanki.

Answers (0)