使用Mustache.Js渲染简单数组

Dee*_*ons 23 arrays mustache

有一个像下面的数组

var arrNames = ["Stackoverflow","StackExchange","Webmaster","Programmers"];

应该如何使用mustache.js javascript模板查找模板.我试过下面但没有线索

  • {{#}}{{key}}{{/}}

max*_*tty 68

文档:

循环遍历字符串数组时,a.可用于引用列表中的当前项.

模板:

{{#musketeers}}*{{.}} {{/ musketeers}}

视图:

{"火枪手":["Athos","Aramis","Porthos","D'Artagnan"]}

输出:

  • 通过Athos
  • 阿拉米斯
  • 波托斯
  • 达达尼昂

var tpl = document.getElementById('simple').innerHTML,
  view = {
    items: ['Stackoverflow', 'StackExchange', 'Webmaster', 'Programmers']
  };

document.getElementById('output').innerHTML = Mustache.to_html(tpl, view);
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.js"></script>
<script type="template" id="simple">
  <h1>Array Values</h1>
  <ul>
    {{#items}}
    <li>{{.}}</li>
    {{/items}}
  </ul>
</script>

<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)