iron-router error in meteor.js project, old template's data get re-called -


i developing meteor.js application, , having strange error. wrote code below , can see have template called groupsmain shows list of different groups, , when click 1 of them, going groupdetail template. working fine, when go groupsmain template inside group detail template clicking navbar, although looks on page, getting error in console. in groupsmain template, not groupdetail template, giving error properties sub-template of groupdetail template using.

exception in template helper: typeerror: cannot read property 'photoid' of undefined @ object.template.groupdetailgeneral.helpers.imageurl   (http://localhost:3000/client/views/groups/groupdetail/groupdetail_includes/groupdetailgenera  l.js?6c735e98e1dbfa1b7514f5e8f58237ea781f3bb6:8:51) @ http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2610:16 @ http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1602:16 @ spacebars.call (http://localhost:3000/packages/spacebars.js?fa6d15347dd76a8b1464ca3a0d4605598857db91:169:18) @ spacebars.mustacheimpl (http://localhost:3000/packages/spacebars.js?fa6d15347dd76a8b1464ca3a0d4605598857db91:106:25) @ object.spacebars.mustache (http://localhost:3000/packages/spacebars.js?fa6d15347dd76a8b1464ca3a0d4605598857db91:110:39) @ template.groupdetailgeneral.html.img.src (http://localhost:3000/client/views/groups/groupdetail/groupdetail_includes/…mplate.groupdetailgeneral.js?7f3022b55bf1958efe4a4a679309ad74d60ef7ea:7:24) @ object.blaze._withcurrentview (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2017:12) @ blaze._htmljsexpander.def.visitattribute (http://localhost:3000/packages/blaze.js?  5ec4e54b22ab2196bcc772669c0619f71666393e:1950:21) @ html.transformingvisitor.def.visitattributes (http://localhost:3000/packages/htmljs.js?fcf2660be84fbc0c33b97ee8932dbd46612f3566:226:44) debug.js:41 exception in template helper: typeerror: cannot read property 'adminid' of undefined @ object.template.groupdetailgeneral.helpers.isadmin (http://localhost:3000/client/views/groups/groupdetail/groupdetail_includes/groupdetailgeneral.js?6c735e98e1dbfa1b7514f5e8f58237ea781f3bb6:20:26) @ http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2610:16 @ http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1602:16 @ object.spacebars.call (http://localhost:3000/packages/spacebars.js?fa6d15347dd76a8b1464ca3a0d4605598857db91:169:18) @ template.groupdetailgeneral.html.div.html.div.html.p.blaze.if.html.a.class (http://localhost:3000/client/views/groups/groupdetail/groupdetail_includes/…plate.groupdetailgeneral.js?7f3022b55bf1958efe4a4a679309ad74d60ef7ea:22:22) @ null.<anonymous> (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2385:44) @ http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1787:16 @ object.blaze._withcurrentview (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2017:12) @ viewautorun (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1786:18) @ tracker.computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) 

and here code.

mainlayout.html

<template name="mainlayout"> {{> yield}} </template> 

maincontroller.js

maincontroller=routecontroller.extend({ layouttemplate:"mainlayout" , onrun:function(){         //seo stuff    } }); 

pagelayout.html

<template name="pagelayout">     {{> yield region="navbar"}}       <div class="container">           {{> yield}}      </div>    {{> yield region="footer"}} </template> 

pagecontroller.js

pagecontroller=maincontroller.extend({ layouttemplate:"pagelayout", // specify templates render in regions of layout yieldtemplates:{     "navbar":{         to:"navbar"     },     "footer":{         to:"footer"     }    }  }); 

detaillayout.html

<template name="detaillayout"> {{> yield region="navbar"}} {{! not yield on here, add sidebar layout}} <div class="container">     <div class="row">         <div style="float:right;">             {{> yield region="detailmenu"}}         </div>          <div class="col-md-12">             {{> yield}}         </div>     </div> </div> {{> yield region="footer"}} </template> 

detailcontroller.js

detailcontroller=pagecontroller.extend({ layouttemplate:"detaillayout", // don't forget yield navbar , footer too, extending yieldtemplates // property parent controller yieldtemplates:_.extend({     "groupdetailmenu":{         to:"detailmenu"     }     },pagecontroller.prototype.yieldtemplates)   }); 

groupsmain.html

<template name="groupsmain"> <div class="row"> {{#if currentuser}}     {{>groupssearch}} {{else}}     <h3>to create or join group, need sign in, or sign up.</h3> {{/if}}     <br/>     <div class="row">     {{>groupslist}}     </div> </div> </template> 

groupslist.html

 <template name="groupslist">  <div class="groups">     {{#each groups}}         {{> groupitem}}     {{/each}}   </div>  </template> 

groupitem.html

 <template name="groupitem">     <div class="container groupitem">         <div class="media col-md-2">             <figure class="pull-left">                 <img  class="media-object img-rounded img-responsive img-placeholder        groupimage" src="{{imageurl}}" alt="/home/wedding.jpg" >             </figure>         </div>         <div class="col-md-6 groupitem">             {{#if ismember}}                 <h3> <a href="{{pathfor 'groupdetail'}}">{{title}}</a></h3>              {{else}}                 <h3 class="list-group-item-heading"> {{title}} </h3>             {{/if}}              <h4 class="list-group-item-text">                 {{desc}}             </h4>         </div>         <div class="col-md-3 text-center pull-right">             <h2> {{numberofmembers}}  <small> members </small></h2>             {{#if currentuser}}                  {{#if ismember}}                     <a href="" class="exit btn btn-danger">exit</a>                 {{else}}                     <a href="" class="join btn btn-primary">join</a>                 {{/if}}              {{/if}}             {{#if isadmin}}<a class="edit" href="{{pathfor 'editgroup'}}">edit</a>{{/if}}         </div>     </div> </template> 

groupitem.js

template.groupitem.helpers({   numberofmembers: function() {     return this.members.length; }, ismember: function() {     return (-1<($.inarray(meteor.userid(), this.members))? 1 : 0); }, isadmin: function() {     return this.adminid == meteor.userid(); }, imageurl: function () {       var image =images.findone({_id: this.photoid});     if(image==null){          return "/home/noimage.jpg";     }     else     {         return image.url();     } }, desc: function(){     if(this.description.length > 150)     return this.description.substring(0, 150) + "...";     else     return this.description; }   });   template.groupitem.events({ 'click .join': function(e) {     e.preventdefault();       groups.update({         _id: this._id     }, {         $addtoset: {members: meteor.user()._id}     });      var timelinedata = {         type: "newuser",         description: meteor.user().username + " joined group",         groupid: this._id      };     meteor.call('createtimeline', timelinedata, function(error, timelineid) {         if (error) {             // display error user             throwerror(error.reason);              if (error.error === 302)                 console.log('hata')         } else {          }     });  }, 'click .exit': function(e) {     e.preventdefault();       groups.update({         _id: this._id     }, {         $pull: {members: meteor.user()._id}     });      var timelinedata = {         type: "deleteuser",         description: meteor.user().username + " exited group",         groupid: this._id      };     meteor.call('createtimeline', timelinedata, function(error, timelineid) {         if (error) {             // display error user             throwerror(error.reason);              if (error.error === 302)                 console.log('hata')         } else {          }     }); } }); 

groupdetail.html

 <template name="groupdetail">  <div class="row" id="groupdetail">    <div class="row-fluid">        <div class="col-md-3">            {{>groupdetailgeneral}}         </div>        <div class="container">        <div class="col-md-9 col-lg-9">             {{! {{> timeline}}        </div>        </div>    </div> 

groupdetailgeneral.html

  <template name="groupdetailgeneral">   <img src="{{imageurl}}" class="img img-thumbnail img-rounded img-responsive" alt="first slide"> <br/> <br/>  <div class="panel panel-primary">     <div class="panel-heading">         group info     </div>     <div class="panel-body">         <h2>{{this.group.title}}</h2>         <h6>{{this.group.description}}</h6>         <p>             admin {{this.group.adminname}}         </p>         <p>{{#if isadmin}}<a class="btn btn-primary edit" href="{{pathfor 'editgroup'   _id=this.group._id}}">edit</a>{{/if}}</p>      </div>    </div>     </template> 

groupdetailgeneral.js

 template.groupdetailgeneral.helpers({  imageurl: function () {       var image =images.findone({_id: this.group.photoid});     if(image==null){          return "/home/noimage.jpg";     }     else     {         return image.url();     } }, isadmin: function() {      return this.group.adminid == meteor.userid();  }  }); 

groupdetailcontroller.js in router.js

 groupdetailcontroller=detailcontroller.extend({  template:"groupdetail",  yieldtemplates:_.extend({      "groupdetailmenu":{          to:"detailmenu"      }  },detailcontroller.prototype.yieldtemplates),   waiton: function() {     return[         meteor.subscribe('singlegroup', this.params._id),         meteor.subscribe('timelinedata')      ]  }, group: function () {     return groups.findone(this.params._id); },  data: function() {     return {         group: this.group()     };  },  onbeforeaction: function (pause) {     if (! meteor.user()) {         if (meteor.loggingin()){}         else             this.render('accessdenied');          pause();     }    }  }); 

router.js

router.map(function() { this.route('home', {     path: '/',     layouttemplate: 'pagelayout',     controller:"pagecontroller" });   this.route('groupdetail', {     path: '/groupsmain/:_id',     controller: groupdetailcontroller });    this.route('groupsmain', {     path: 'groupsmain',     waiton: function() {         return [meteor.subscribe('groups')];     },data: function() {         return {             groups: groups.find()         };     },      layouttemplate: 'pagelayout',     controller:"pagecontroller" }); }); 

i think right iron router doesn't automatically wait subscriptions declared on waiton, asking property of yet undefined (not fetched server) object.

on iron router 0.7.0, i've enabled router wait ofr subscriptions adding:

router.onbeforeaction(function (pause) { if (!this.ready()) { this.render('loading'); pause(); } });

also sure of defining 'loading' template (i don't remember if ir provided one).

for reference, here long discussion on issue @ ir repo.

edit: 1 of mantainers scheduled issue next release change semantics of waiton, make automatic. ref: https://github.com/eventedmind/iron-router/issues/819


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -