JavaScript template engine handlebars usage examples and techniques

Source: Internet
Author: User

When we were developing the DOM operation, it was no problem with a simple JS application, but what if you needed to manipulate a lot of chunks in my document every time you updated the view? At this time the JS template came in handy.

Source Address: http://rfyiamcool.blog.51cto.com/1030776/1278620

This is an example where we can embed the JSON data in the template as we think it is.

<! 
  DOCTYPE html>  

See this example, we feel very happy it ~ is so. We can get the data from the back end and throw it to the front end without having to write the various "<>" separation symbols.

To traverse the data inside, print out

<script id= "Each-template" type= "Text/x-handlebars-template" >
  {{#each people}}
    ... output person ' s info here ...
  {{/each}}}
</script>

Data rendering if data is available

<script id= "Each-template" type= "Text/x-handlebars-template" >
  {{#if people}}
    ... output person ' s info
  here ... {{/if}}}
</script>

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.