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