簡體   English   中英

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

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

我正在嘗試在模板上生成許多圖,我的第一個圖是默認圖,我想當我單擊區域時生成另一個圖,該圖存在於另一個模板中。 我怎樣才能做到這一點 ?

我嘗試以其他方式退還我的模板。

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]};
}});

您可以為此使用Template.dynamic。

// html

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

// 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