arttemplate--Call error Arttemplate,syntax error,template error when using arttemplate because of a special format for JSON object properties

Source: Internet
Author: User
Tags access properties

Let's look at the following code first

data = {    "siteName": "West Cloud Valley Two",        "PM10": "10017",        "PM2.5": < Li>{{sitename}}</li> ' +    ' <li>{{PM10}}</li> ' +    ' <li>{{[\ ' pm2.5\ ']}}</li> '== render (); Console.log (HTML);

The result appears as Template Error

The reason for the analysis may be in the field "PM2.5". In JavaScript. Represents the Get property, such as User.Name, which gets the name property of the user object.

Then there is a solution, let's try the following:

data = {    attr: {        "siteName": "West Cloud Valley Two",        "PM10": "10017",        "PM2.5": 17< c11>    = ' <li>{{attr.siteName}}</li> ' +    ' <li>{{attr. Pm10}}</li> ' +    ' <li>{{attr[\ ' pm2.5\ ']}}</li> '== render (data);

Ok! The code runs correctly. The template is parsed correctly.

JavaScript has two ways to access properties, one is through . Access, and one that is accessed using [' Property name ']. So there are fields with special characters that we can access in the second way.

If this article is helpful to you, you can give me a reward.

Technical Exchange QQ Group: 15129679

arttemplate--Call error Arttemplate,syntax error,template error when using arttemplate because of a special format for JSON object properties

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.