Expression
In riot.js, html tags can use more powerful expressions to set values.
Expressions can be used in innerText, attributes, and are 100% original JavaScript syntax.
Give me a few small examples:
1 2 |
|
The usage methods are also quite rich:
1 2 3 4 5 6 |
|
riot.js expressions can make your html as clean and efficient as possible .
Of course, if your expression is too complex, you can consider placing the calculation in the update event, or using a separate calculation method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
The output is as follows:
Boolean attributes
Attributes such as checked, selected, etc. are called in roit.js Boolean properties.
If the expression value of the Boolean attribute is false, the attribute will be ignored:
1 2 3 4 |
|
will be generated:
1 |
|
The W3C specification states that as long as the Boolean attribute exists, then it must be true, even if its value is even false, it is still true.
To put it simply, even if we set checked=false, the final effect shown by the browser is still checked.
In view of this, roit.js has optimized the Boolean attribute when generating it. If it is a Boolean attribute and its expression satisfies the conditions:
1 |
|
will not Generate this Boolean property.
Beginner’s Encounter
Property Settings
1 |
|
Such settings are prohibited, and the generated code will be like this:
1 |
|
means complete I don't understand. Is there any problem?
Double quotes
1 |
|
Looks normal, is there anything wrong?
But the result code is:
1 |
|
Again, riot.js has a grudge against double quotes! ! ! ! [In most cases]
The above is the content of riot.js learning [4] Expression + Boolean attribute. For more related content, please pay attention to the PHP Chinese website (www. php.cn)!