每个模板的把手在 Node 中不起作用

Handlebars for each template not working in Node

我正在使用 Node.js、Express 和 Handlebars 在客户端呈现模板。我没有收到任何错误,但是模板没有被填充。

查看:detail.hbs

<table id="attachmentTable" class="table table-condensed box-bottom-space"> 
  <tbody>
    ...                         
  </tbody>
</table>

// The back slash before the curly brackets are required, without it errors out.
<script id="rowTemplate" type="text/x-handlebars-template">
  \{{#each this}}
  <tr>
    <td class="attachments">
      <i class="fa fa-file-text"></i> &nbsp;
      <a target="_blank" href="/uploads/\{{this}}">\{{this}}</a>
      <a class="deleteAttachmentIcon text-danger" href="javascript:;" data-deletefile="\{{this}}"><span class="fa fa-remove"></span></a>
    </td>
  </tr>
  \{{/each}}
</script>

<script type="text/javascript" src="/js/handlebars-v4.0.5.min.js"></script>
<script>
  $(function($) {
    $.ajax({
      url: '/processes/upload/{{processes._id}}',
      type: 'POST',
      data: formData,
      processData: false,
      contentType: false,
      success: function(response){
        if(response.success){
          console.log(response.file);
          var rTemplate = $("#rowTemplate").html();
          var crTemplate = Handlebars.compile(rTemplate);
          $("#attachmentTable body").append(crTemplate(response.file));   
        }           
      }
    });
  });
</script>

这是服务器的响应:

{"success":true,"msg":"The file(s) has been Upladed Successfully!","file":["June Updates1-1519927100102.docx","export-11-03-2017-1519927100103.xls"]}

我错过了什么?

无需仔细查看其他代码:

$("#attachmentTable body").append(crTemplate(response.file));

您可能是想 select tbody,而不是 body