javascript - Iron meteor's Route doesn't fire rendered event of the template -


here's case. i'm building template should render chart based on data can identifier.

the example show here simplified version of code discribe problem.

here html:

<head>   <title>example</title> </head> <body> </body>  <template name="layout">   <a href="/firsttext">first text</a>   <a href="/anothertext">another text</a>   {{> yield}}  </template>  <template name="example">   <span id="text">basic text</span> </template> 

and javascript:

if (meteor.isclient) {   router.configure({     layouttemplate: 'layout'   });    router.route('/:text', function() {     this.render('example', {       data: this.params.text     });   });    template.example.rendered = function() {     $('#text').html(this.data);   } } 

this code renders whatever put in url "p" tag. if go on first link text "firsttext". after if go on link text same. text changed if reload page.

that because when render template via iron:router's method this.render('template') meteor creates , renders template cause fire of created , rendered events, if go other url same router, meteor doesn't destroy template , recreates him, change data. rendered event doesn't fire on change of url.

i can use rendered event , not helpers because helpers can't element jquery.

now i'm using solution i'm wrap logic in rendered event tracker.autorun() , use session.set('text', this.params.text) in router , session.get('text') in autorun function rerender text every time url change. solution gives additional problems. , think router's this.render('templatename') should fire rendered event.

could please me make first variant work without reactive data. maybe there solutions can rerender template?

meteor avoids re-rendering templates as possible , great because makes code faster. key here use reactivity. can write in html:

<template name="example">     <span id="text">{{text}}</span> </template> 

and in js file:

template.example.helpers({     text: function() {         return this;     } }); 

you don't need rendered function , don't need jquery.

and if want can access element helper jquery. in rendered

template.example.rendered = function() {     this.rendered = true; } 

and in helper

whateverhelper: function() {     var tmpl = template.instance;     tmpl.rendered && tmpl.$('#something').makefun(); } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -