代码之家  ›  专栏  ›  技术社区  ›  user752746

每个模板的把手不在节点中工作

  •  0
  • user752746  · 技术社区  · 8 年前

    我正在使用Node。js、Express和Handlebar在客户端渲染模板。我没有收到任何错误,但模板没有填充。

    视图:详图。哈佛商学院

    <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”:“文件已成功上传!”,“文件”:[“June Updates1-1519927100102.docx”,“export-11-03-2017-1519927100103.xls”]}

    我错过了什么?

    1 回复  |  直到 4 年前
        1
  •  1
  •   Litty    8 年前

    无需仔细查看其他代码:

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

    你可能想选择 tbody 这里,不是 body .

    推荐文章