In riot. js, html tags can be set using powerful expressions. The expression can be used in innerText and attributes, and is 100% original JavaScript syntax.
Expression
In riot. js, html tags can be set using powerful expressions.
The expression can be used in innerText and attributes, and is 100% original JavaScript syntax.
Here are several small examples:
{/* The expression can be written here */}
The usage is quite rich:
{Title | 'da Zong Xiong '} {isReady? 'Ready': 'loading'} {new Date ()} {this. getName ()} {Math. round (10)} {message. length> 100 & 'the message is too long ~ '}
Riot. js expressions make your html as clean and efficient as possible.
Of course, if your expression is too complex, you can consider placing the calculation in an update event or an independent calculation method.
{Value}
{This. getText (this. text )}
// Calculate the complex expression this. on ("update", function () {var d = new Date (); this. value = d. getFullYear () + "-" + (d. getMonth () + 1) + "-" + d. getDate () ;}); this. text = "da zongxiong"; // The getText method depends on the getText (text) {return "hello" + text ;}
The output is as follows:
Boolean attribute
Attributes such as checked and selected are called Boolean attributes in roit. js.
If the expression value of the Boolean attribute is false, the attribute will be ignored:
Will generate:
The W3C specification specifies that, as long as the Boolean attribute exists, it must be true, and its value is even false, but it is still true.
Simply put, even if we set checked to false, the browser will still be checked.
To address this, roit. js optimizes the Boolean attribute during production. If it is a Boolean attribute and its expression meets the following conditions:
{ value == false }
Will not generate this Boolean attribute.
Newbie
Attribute settings
This setting is forbidden. The generated code is as follows:
It means you can't understand it?
Double quotation marks
It looks quite normal. Is there any wood?
But the result code is:
I once again stressed that riot. js has a hatred against double quotation marks !!!! [In most cases]
The above is the content of riot. js learning [4] expression + Boolean attribute. For more information, see PHP Chinese website (www.php1.cn )!