JQuery. tmpl () usage example _ jquery

Source: Internet
Author: User
With the Smarty templates, JavaScript can also use the templates to solve PHP Data splicing problems, such as jQuery-based jquery. tmpl dynamic request data to update pages is now a very common method, such as dynamic loading of blog comments by PAGE, rolling loading of Weibo, and loading of scheduled requests.

In these cases, the data returned by the dynamic request is generally not formatted as JSON or XML. In short, data is spelled out on the server rather than on the browser. However, from the perspective of the transmission volume, it is not cost-effective to return HTML. In terms of web transmission, JSON rather than XML is used.

The browser generates HTML based on JSON. It is annoying that when the structure is not complex, the structure is complicated and the browser wants to die, you need to carefully write JavaScript code that is barely maintained.

For example, with the Smarty templates used to solve the PHP Data spelling problem, JavaScript can also use the templates to solve these problems, such as jQuery-based jquery. tmpl, now accepted as the official template plug-in. The detailed API is in the Templates of jQuery. the built-in demo also demonstrates various usage.

I have used it several times, and I feel very good. I wrote the structure in HTML rather than JavaScript, and then filled the data with JSON variables, the code looks much better.

Tmpl provides several tags:

$ {}: Equivalent to {{=}}. It is an output variable encoded in html.
{Html}: output variable html, but no html encoding, suitable for output html code.
{If }{{ else }}: provides the branch logic.
{Each}: provides loop logic and $ value is used to access iteration variables.

How to Use jquery tmpl:

Template definition:

Method 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.