简体   繁体   English

如何使用另一个模板上的html更改流星中的模板主体?

[英]How can I change the body of template in meteor with a html on another template?

I'm trying to generate many graph on a template, my first graph is default , I'd like when I click on a zone I generate another graph who exist in a another template. 我正在尝试在模板上生成许多图,我的第一个图是默认图,我想当我单击区域时生成另一个图,该图存在于另一个模板中。 How can I do that ? 我怎样才能做到这一点 ?

I try to return my template with my other grahp. 我尝试以其他方式退还我的模板。

Template.test.events({'click .zone' : function (e){
  console.log("J'ai cliqué sur le template Test ... on va essayer d'ouvrir une pop up");
  e.preventDefault();
  //$('#animalsModal').modal('show');
  return {template: Template[createGraph]};
}});

You can use Template.dynamic for this purpose. 您可以为此使用Template.dynamic。

//html // html

<template name="graphDisplayer">
{{> Template.dynamic template=helperToGetDynamicTemplate}}
</template>

//JS // JS

Template.graphDisplayer.onCreated(function(){
  this.templateNameOfGraph = new ReactiveVar('yourDefaultTemplate');
});

Template.graphDisplayer.events({
  'click .zone':function(e,t) {
    t.templateNameOfGraph.set('yourOtherTemplate');
  }
});

Template.graphDisplayer.helpers({
  helperToGetDynamicTemplate:function(){
    return Template.instance().templateNameOfGraph.get();
  }
});

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

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