这是我想在Mustache.js中做的,但没有看到文档的方式.
var view = {items:['Mercury','Venus','Earth','Mars']};
var template = "<ul> {{#items}}<li>{{i}} - {{.}}</li>{{/items}} </ul>";
var html = Mustache.to_html(template,view);
Run Code Online (Sandbox Code Playgroud)
期望的输出:
<ul>
<li>0 - Mercury</li>
<li>1 - Venus</li>
<li>2 - Earth</li>
<li>3 - Mars</li>
</ul>
Run Code Online (Sandbox Code Playgroud)