Riot. js learning [4] expression + Boolean attribute

Source: Internet
Author: User
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 )!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.