我在使用 Handlerbars.js 的 each 块助手时遇到了麻烦
<html>
<head>
<script>
</script>
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
{{#each people}}
<p>{{firstName}} {{lastName}}</p>
{{/each}}
</div>
</script>
<script src="lib/jquery-1.8.2.min.js"></script>
<script src="lib/handlebars.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
var people = [
{firstName: "Yehuda", lastName: "Katz"},
{firstName: "Carl", lastName: "Lerche"},
{firstName: "Alan", lastName: "Johnson"}
]
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
var html = template(people);
$('#content').html(html);
});
</script>
</head>
<body>
<div id="content">
</div>
</body>
</html>
如果我将模板更改为下面的代码,一切顺利:
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
{{#.}}
<p>{{firstName}} {{lastName}}</p>
{{/.}}
</div>
</script>
如何使用 each 辅助块?