Skip to Content
Jan 19, 2021 at 12:12 PM

Is it possible to use Binding-Expressions as conditions in my Javascript code?

729 Views Last edit Jan 19, 2021 at 12:16 PM 5 rev

Hi Community,

i have some code in my UI5-Controller which dynamically adds UI-Controls to my UI5-View. This works fine.

Now i would like to use conditions to decide if i dymamically add an UI-Control or not or another.
This conditions should be data driven.
So my idea is to use something like an ExpressionParser-Class from UI5 to evaluate a condition which functions like expression-binding in UI5-Controls. But i did not found such class in UI5.

So here some kind of Pseudo-Code with a Peudo-Class ExpressionParser to make a better understanding of what i mean:

/* evaluate if to insert Fragment A or Fragment B based on property 'scenario' of model 'mymodel' */
var bUseFragA = ExpressionParser("{= ${mymodel>scenario} === 'A'}"); if (bUseFragA) { Fragment.load("FragmentA"); }
else {

Of course it would often be possible and even simpler to use the "visible" or "enabled" properties and to use expression binding on them. But in this case i don't want to create Controls when condition is not met.

Does someone have an idea to implement this. If there is a class which is used by UI5 to evaluate bindings to control properties and how to use it for something like this?

kind regards