Experience using a triplet of expressions of ivx

Written in the form of a triple expression data binding can help us be more convenient, intuitive control cases, one is often used function ivx, additional data binding, we will often bundled content, today to talk about specific ternary expression. This small demo can make the top five icons randomly by clicking a button.

1. First we build such a layout, is placed above the 5 different colored icons, buttons, and add text below, the last value of a variable data needed for binding.
Here Insert Picture Description
2. The second step, we add a click event to the button, so that the numerical value of the variable range is a random integer from 1-5. Here the content and value of the variable text components of a data-bound to do, to help us see the results directly generate random numbers.
Here Insert Picture Description
Here Insert Picture Description
3. The third step we databind visible attributes five icons. When the data is not binding, the value of the visible property is a Boolean value that is true if visible, is false representation is not visible, so the results of our triplet of expressions to the final result should also be true or false.
Here Insert Picture Description
Here is the wording of a triplet of expressions of the "display control == 1 true:? False". Look "?" In front of "display control == 1", in the programming language "=" is the assignment symbol "==" indicates only equal, meaning that the value is part of the variable "display control" is equal to 1, " ? "is to determine whether this relationship was established. The latter part "true: false" if it corresponds to the preceding formula is established, the final result of the expression is ":" before the true, otherwise it is ":" behind false. Therefore, the "display control" is equal to 1 when an icon is visible, the "display control" is equal to a value other icon 1 is not visible.
Here Insert Picture Description
Here Insert Picture Description
4. form a triplet of expressions used above is the standard form "Conditions Result 1:? 2 results." However, because of the visible property itself is a Boolean value of a variable, while the point in said "control variable == 1" part is used to determine the "control variable" is equal to 1 is established, in fact, this result established itself is a Boolean value of a variable. For example, "The display control == 1" holds, "the display control == 1" is true, the contrary is false. So we can use data binding directly with such an approach in the figure below.
Here Insert Picture Description
Compare, then, such an approach is the result of the formula directly assigned to the icon of the visible property, the result of the formula is true, visible property equal to true, the result of the formula is false, the visible property equal to false. If the result is the standard written expression is true, let the visible property equal to ":" in front of the completed value of true ,, If the result of the formula is false, then let the visible property equal to ":" false value of the completed later.

5. In fact, a triplet of expressions largely determine the conditional expression is established, so it is not only the conditional expression equation, you can use "! =", ">", "<", "> =" And "= < ", but also with the" & "(and) and" || "(or) connecting together the simple equation (calculation level can be determined by parentheses), to make the situation more complicated determination of conditions.

It summarizes the
flexible use of a triplet of expressions can make our case in many parts of the structure is more compact, the relationship between the components and variables will be clearer. And once you understand the reference form, and various modifications are actually very easy to grasp, of course, finally had to practice more Oh.

Guess you like

Origin blog.51cto.com/14556317/2484770