0

我正在使用 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":"文件已成功升级!","file":["June Updates1-1519927100102.docx","export-11-03-2017-1519927100103.xls "]}

我错过了什么?

4

1 回答 1

1

不用太看重其他代码:

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

您可能打算在tbody这里选择,而不是body.

于 2018-03-01T19:07:17.480 回答