如何在另一个模板上使用 html 更改 meteor 中的模板主体?
How can I change the body of template in meteor with a html on another template?
我正在尝试在一个模板上生成许多图表,我的第一个图表是默认图表,我希望当我单击一个区域时生成另一个存在于另一个模板中的图表。我该怎么做?
我尝试 return 我的模板与我的其他 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]};
}});
您可以使用 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();
}
});
我正在尝试在一个模板上生成许多图表,我的第一个图表是默认图表,我希望当我单击一个区域时生成另一个存在于另一个模板中的图表。我该怎么做?
我尝试 return 我的模板与我的其他 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]};
}});
您可以使用 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();
}
});