把手:每个不起作用的对象数组

时间:2018-05-10 19:53:28

标签: javascript jquery handlebars.js

由于某种原因,我无法让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>

非常感谢任何建议,提前谢谢!

0 个答案:

没有答案