javascript - How do I implement nested #each blocks with Meteor and MongoDB reference? -
so, have following handlebarsjs helper:
<ul class="list-unstyled"> {{#each gralskills}} <li class="pl-14"><i class="flaticon-checkmark4"></i> <a data-toggle="collapse" href="#collapse{{number}}"> {{gralskillname}} </a> <div id="collapse{{number}}" class="panel-collapse collapse small pl-21"> <span class="block">{{gralskilldescription}}</span> <span class="uppercase block">indicadores - <a href="#" class="flaticon-plus34 text-danger not-underline" id="new-gral-skill-indicator"></a></span> <ul class="list-unstyled pl-14"> {{#each gralskillindicators}} <li>- {{indicatorname}}</li> {{/each}} </ul> </div> </li> {{/each}} </ul>
with it's respective js code:
template.courseedit.helpers({ gralskills: function(){ var thiscourseid = session.get('templateid'); // console.log(thiscourseid); return gralskills.find({"courseid": thiscourseid}); }, gralskillindicators: function() { var thisgralskillid = session.get('templateid'); return indicators.find({'courseid': thisgralskillid}); } });
the view looks this:
screenshot http://soygus.com/img/emdinscreenshot.png
which means i'm getting both data view. issue comes inside loop, can't find how reference indicadores respective parent.
take mongodb indicators
collection:
/* 0 */ { "indicatorname" : "la alumna presenta en clase con seguridad y confianza", // belongs gralskill (autoestima) "gralskillid" : "kgtapkmeml2qwvsxa", "courseid" : "3vcn5v5brsid5tfgb", "_id" : "rpnkirhdtmrsjgn7i" }
the indicator created belongs first list item in view, however, i'm getting displayed in of list-items.
this gralskills collection reference:
/* 0 */ { "gralskillname" : "autoestima", "gralskilldescription" : "la capacidad de confiar en las habilidades propias.", "submitted" : 1398089534856, "number" : 1, "courseid" : "3vcn5v5brsid5tfgb", "_id" : "kgtapkmeml2qwvsxa" } /* 1 */ { "gralskillname" : "emprendimiento", "gralskilldescription" : "la capacidad de proponer soluciones con ideas y modelos de negocio", "submitted" : 1398094493828, "number" : 2, "courseid" : "3vcn5v5brsid5tfgb", "_id" : "zjgfgnze8tmejqtwh" }
how can make list-items display correspondent indicator?
thanks in advance.
not sure if i'm getting right, think in gralskillindicators
helper, seems shouldn't assigning global session variable session.get('templateid')
thisgralskillid
, since session variable same items of loop.
instead, should write var thisgralskillid = this._id
, should let access _id
of parent data context. if makes sense?
Comments
Post a Comment