javascript - Get template data from helper -
i'm trying update template's datacontext on oncreated hook:
template.segment.oncreated(function () { var tp = this; this.test = "test"; meteor.call('gettreecategdata', function (error, data) { tp.externalapidata = data; tp.chart = new chart(); //... }); });
i want keep these references on parents templates, access them childs templates.
now "update" datacontext value set on oncreated.
template.segment.helpers({ parentdatacontext: function(){ this.chart = template.instance().chart; //undefined this.apidata = template.instance().apidata; //undefined //but executed later, when open chrome object inspector reference, not undefined anymore console.log("parentdatacontext: ", template.instance()); return this; } });
my template:
<template name="segment"> {{#with parentdatacontext}} {{> childtp}} {{/with}} </template>
to use them on child template event's handler:
template.childtp.events({ 'click .js-close': function(e, tp){ console.log(" tp parent data: ",template.parentdata(1)); } });
i'm stuck on process, i'm not able print added attribute set on oncreated helper... guess helper call template before on created end...
any idea how fix that, or better way want do?
thanks
how reactivevar
?
template.segment.oncreated(function () { var tp = this; this.apidata = new reactivevar(); meteor.call('gettreecategdata', function (error, data) { tp.apidata.set(data); tp.chart = new chart(); //... }); }); template.segment.helpers({ parentdatacontext: function(){ this.chart = template.instance().chart; this.apidata = template.instance().apidata.get(); // data - {{with parentdatacontext}} // no data - {{else}} if (this.apidata) { return this; } } });
and template code
<template name="segment"> {{#with parentdatacontext}} {{> childtp}} {{else}} loading or something... {{/with}} </template>
Comments
Post a Comment