1

How can I use multiple nested properties of an observable in a binding expression?

map is an observable with two properties, isEnabled and isPaused, that is nested within an observable, that is itself bound to page.bindingContext. If either properties are true I wish to do something. In this case, change the label's text.

<Label text="{{ map.isEnabled, map.isEnabled || map.isPaused, map.isPaused  }}" />

^ Text output changes from true to false correctly as the properties change.

<Label text="{{ map.isEnabled, map.isEnabled || map.isPaused, map.isPaused ? 'Text one' : 'Text two' }}" />

^ Text output is still true or false. The ternary is completely ignored.

What is the correct way to do this?

2
  • See docs: docs.nativescript.org/core-concepts/… ternary operator var1 ? var2 : var3 Evaluating the value of var1 and if true, returns var2, else returns var3. Commented Apr 4, 2017 at 17:03
  • Sorry, did you find the solution? Commented May 9, 2019 at 13:07

1 Answer 1

1

I'm not familiar with the comma expression you're using. Can you please explain that to me? How is it different from this I wonder:

<Label text="{{ map.isEnabled || map.isPaused ? 'Text one' : 'Text two' }}" />
Sign up to request clarification or add additional context in comments.

2 Comments

Have a read of the "Using expressions for binding" section of the docs. The comma syntax is explained there. docs.nativescript.org/core-concepts/…
Thanks, interesting concept.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.