【问题标题】:How can I change the body of template in meteor with a html on another template?如何使用另一个模板上的 html 更改流星中的模板正文?
【发布时间】:2016-12-22 16:31:47
【问题描述】:

我正在尝试在模板上生成许多图表,我的第一个图表是默认的,我希望当我点击一个区域时,我会生成另一个存在于另一个模板中的图表。我该怎么做?

我尝试用我的其他图形返回我的模板。

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

【问题讨论】:

    标签: javascript jquery meteor d3.js c3.js


    【解决方案1】:

    您可以为此目的使用 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();
      }
    });
    

    【讨论】:

    • 当我执行此代码时,我的第一个图表数据发生了变化。我使用 jquery 指定我的 div。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    相关资源
    最近更新 更多