How to do foreach in Meteor with Mongo? -
have collection
peoples = new mongo.collection('peoples'); peoples.insert({ name: ["mark", "john", "kate"] }); i want show names in name
<template name="ptable"> <tr class="trjob"> <td> {{#each names}} {{> peoplename}} {{/each}} </td> </tr> </template> <template name="peoplename"> <div>{{name}}</div> </template> what in temlate helpers
template.ptable.helpers({ names: function(){ return posts.tags; } }); template.peoplename.helpers({ name: function(){ return posts.tags.find(); } }); i know have sh*** code in template helpers, idea how make ?
it must (in dom)
<td> <div>mark</div> <div>john</div> <div>kate</div> </td>
simple array example
template.home.helpers({ names: function(){ return [1,2,3]; } }); <template name="home"> {{#each names}} {{this}} {{/each}} </template> will print:
1 2 3
each item becomes "this" inside each loop. if call template within loop, "this" populated item
Comments
Post a Comment