小胡子render()在数组不工作

时间:2012-03-03 18:26:58

标签: javascript templates mustache

我在这里做错了什么?

<!doctype html>
<html>
<head>
  <title>Testing</title>
  <script src="mustache.js"></script>
</head>
<body>

<script type="text/javascript">
  var musk = ["athos", "porthos", "some other guy"];

  var output = Mustache.render("<div>The three <br>{{#musk}}<p>{{.}}</p>{{/musk}}<br> Those guys</div>", musk);

  console.log(output);

</script>

</body>
</html>

这给了我:

<div>The three <br><br> Those guys</div>

如果我没弄错的话,我几乎完全从github页面复制了这个例子。此外,我很确定模板内部允许使用html,而不是内容或视图内部。对?

1 个答案:

答案 0 :(得分:5)

您需要像这样命名输入数组:

var musk = {musk: ["athos", "porthos", "some other guy"]};