Js template engine handlebars. js practical tutorial -- using indexes in a loop

Source: Internet
Author: User

Usage of indexes in the loop-by Yang Yuan-about sequence number name gender age of the index in the loop

 

 

Serial number indicates the index of the current loop during the loop process. To put it bluntly, it indicates the number of loops currently, generally starting from 0, as is the case in Handlebars. js.

What is the purpose? The most common is to add a sequence number to each row when displaying a table, which clearly shows the total number of records on the page, as shown in the preceding example.

In addition, to differentiate different IDs in a loop, a sequence number is exactly required to ensure that IDs are not repeated. We should know that many events can be identified by IDs, for example, the Listgroup control.

In Handlebars. js, you can use {@ index} to obtain the current index. That is to say, the @ index variable represents the current index.

In the above example, the table sequence number is not good from 0, so a Helper is registered and the index is + 1.

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.