handlebars.js - Meteor Spacebars - {{#each}} params -


this code:

html

card 1:

<!-- shopping list --> <div id='shopping' class='card'>   {{#each task}}   <ul class="card__task">     <li>{{tasktext}}</li>     <i class="fa fa-minus delete-task"></i>   </ul>   {{/each}} </div> 

card 2:

<!-- medicine list --> <div id='medicine' class='card'>   {{#each task}}   <ul class="card__task">     <li>{{tasktext}}</li>     <i class="fa fa-minus delete-task"></i>   </ul>   {{/each}} </div> 

template.helper

  task: function() {     return tasks.find({}, {       sort: {         createdat: -1       }     });   } 

tasks collection example

ex.1:

   ...   "taskgroup": "medicine",   "tasktext": "medicine task 1",    ... 

ex.2:

   ...   "taskgroup": "shopping",   "tasktext": "shopping task 1",    ... 

so, got collection store tasks taskgroup corresponding textarea input id. each iterates on every task have in tasks collection , 2 cards show tasks.

question:

how can tell each block iterate on tasks have taskgroup equal cards id?

something like:

  task: function() {     return tasks.find({     taskgroup: *the card each block located*.getattribute("id");     }, {       sort: {         createdat: -1       }     });   } 

you can create blaze helper filter taskgroup

tasks: function(taskgroup) { return tasks.find({ taskgroup: taskgroup; }, {   sort: {     createdat: -1   } }); 

}

that way can call on template this

{{#each tasks 'medicine'}} ... {{/each}} 

Comments