Let’s say you are in a situation where you want to show the user the corresponding
image when the user selects a particular option in NativeScript Core.
We’ll use the <Image> widget to display the image, and <SegementedBar> to
display the options.
Initial Setup
Note: At the time of writing this article it is not possible to bind
to selectedIndexChange event from the xml file in NativeScript core.
Challenge
Before you proceed reading this further, try to do this yourself.
Did you manage to do it? If yes, well done! If no, read on!
Solution
The intuitive approach here would be to bind the text property to
{{ text[index] }} and bind the src property to {{ src[index] }}
However, using multiple variables in an expression like that is not supported
in NativeScript. So the way we bind is by specifying the different variables that
we will be using, before using them in an expression.
So the correct way to bind it is,
text="{{ text index, text[index] }}" for the label src="{{ images index, images[index] }}" for the image
(Note: The order in which you specify the variables does not matter)