由于某种原因,我无法让Handlebars循环我的记录数组。我也在jsfiddle https://jsfiddle.net/Tonyvu/ncr6nyta/上有我的代码。
我有以下数组:
Array(2)
0: {userid: "jd1234", fullName: "John Doe"}
1: {userid: "jd4567", fullName: "John doe"}
length: 2
__proto__: Array(0)
HTML表格
<table id="Tbl">
<tbody>
<tr>
<td>Bobby Jones - bj1234</td>
</tr>
</tbody>
</table>
我的脚本如下所示:
<script id="template" type="text/x-handlebars-template">
{{#each records}}
<tr>
<td>{{fullName}} - {{attuid}}</td>
</tr>
{{/each}}
</script>
<script>
$(function($) {
var devlist = [
{userid: "jd1234", fullName: "John Doe"},
{userid: "jd4567", fullName: "John doe"}
];
var csTemplate = $("#template").html();
var compiledTemplate = Handlebars.compile(csTemplate);
$("#Tbl tbody").append(compiledTemplate({records:devlist}));
});
</script>
非常感谢任何建议,提前谢谢!