Mustache method to get the specified elements of an array object within the JSON data

Source: Internet
Author: User

Because of the recent project re-use of mustache, this problem was found, mustache cannot get the elements of the specified index of the array key values within the JSON data

Then the Internet to check the data to summarize the two methods

1, the data is array-to-image

var obj = [{name: ' foo '}, {name: ' Bar '}]; var tmp = ' {#1}}{{name}}{{/1}} '; Console.log (Mustache.render (tmp, obj)); // Bar

This method personally feels that there are certain limitations

-----Reference: Http://stackoverflow.com/questions/6516297/can-mustache-iterate-a-top-level-array

2, the data is an array object within the object

var obj1 = {    ' authors ': [{name: ' foo '}, {name: ' Bar '}]};  for (var i = 0, len = obj1.authors.length; i < Len; i++) {         = i;}; var tmp1 = ' {{authors.0.name}} '; Console.log (Mustache.render (TMP1, obj1)); // Foo

This code personally feel is a relatively perfect one, but not very suitable for big data

------Reference: Http://www.kuqin.com/shuoit/20131012/335580.html

Mustache method to get the specified elements of an array object within the JSON data

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.