iterate through JSON array with mustache

后端 未结 3 1609
挽巷
挽巷 2020-12-17 15:18

I am new to Mustache, please bear with me :)

I have an array in my JSON

\"prop\":{\"brands\":[\"nike\",\"adidas\",\"puma\"]}

if I h

3条回答
  •  佛祖请我去吃肉
    2020-12-17 15:56

    Here is a working fiddle: http://jsfiddle.net/Qa4UX/

    Basically, you need to iterate over the brands array. Since your array is raw and does not have objects inside you have to reference each string like so:

    {{#props}}
      
      {{#brands}}
    • {{#.}} {{.}} {{/.}}
    • {{/brands}}
    {{/props}}

    You can also find many more examples over here: https://github.com/janl/mustache.js#mustachejs---logic-less-mustache-templates-with-javascript

提交回复
热议问题