简体   繁体   English

在html页面中呈现模板

[英]render a template inside a html page

This Meteor client code renders a report template from raw html. 此Meteor客户端代码从原始html呈现report模板。 A click #sginHere event needs to place a canvas which is coded in a different file with its own template and events into the report template in place of event.target.appendChild . click #sginHere事件需要将一个画布(该画布已编码在具有自己的模板和事件的其他文件中)替换为report模板(代替event.target.appendChild

Is there a way to do this and how? 有办法做到吗?

Template.report.helpers({
  value: function() {
    return rawHTML;
  }
});

Template.report.events({
  'click #signHere': function(vent) {

    //create a canvas_element with all its styling and events
    event.target.appendChild(canvas_element);  //<-- redundant

    //render it from already existed template
    event.target.appendChild(canvas_from_different_template)  //<-- my wish
  }
});

//canvas file
let ctx = null;
let signatureCnvs = null;
Template.canvas.onRendered(function() {
  //do stuff
});

Template.canvas.events({
  'mousemove canvas': function(event) {
    //do stuff
  }
});
canvas.signature {
  height: 15em;
  width: 25em;
  border: 1px solid black;
}
<template name="report">
  {{{value}}}
</template>

<template name="canvas">
  <canvas class="signature"></canvas>
</template>

Use Dynamic Template and helpers. 使用动态模板和助手。 Let me show you: 让我演示给你看:

let clickSign = false;
Template.report.helpers({
   wantToSign: function() {
      return clickSign;
 }
});
Template.report.events({
   'click #signHere': function(event) {
      clickSign = true;
   }
});
// Rest of your code ...

And in your html: 并在您的html中:

<template name="report">
   {{{value}}}
   {#if wantToSign}}
      {{> canvas}}
   {{/if}}
</template>
<template name="canvas">
   <canvas class="signature"></canvas>
</template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM