2

Meteor newbie here.

I have a template for a home page. The home pages has several "day"s in it, which each have "task"s. I want to display the appropriate task in the day that it belongs to, but I don't know how to do this.

I also only want to retrieve the relevant tasks with one database query if possible (ie all tasks within two weeks).

I found a couple other questions possibly related to this including this and this but I can't discern any useful related info.

I have a collection for tasks, and as part of the home page I retrieve a two week span of tasks. Then I sort them into day buckets.

buckets = [[...], [...], [...], ... ] # array of arrays of task objects

Now I don't know what to do. In the home template, I think I can do

Template.home.helpers(
    tasks: ()->
        #return buckets, defined above
)
(home.coffee)

<template name="home">
    {{#each tasks}}
         {{> day}}
    {{/each}}
</template>
(home.html)

to iterate over the day buckets, but how do I access the task objects from each day template?

<template name="day">
    {{#each ???}}
        {{> task}}
    {{/each}}
</template>

<template name="task">
    {{name}}
</template>

How can I access the data from the current iteration of the each loop from the parent template? Am I structuring this incorrectly? Should I just make separate db calls for every day?

Community
  • 1
  • 1
Oliver
  • 2,182
  • 5
  • 24
  • 31

1 Answers1

3

This should do the trick:

<template name="day">
    {{#each this}}
        {{> task}}
    {{/each}}
</template>

Edit: this is the incorrect original answer.

Let task have fields called name, important and dueToday. Then you may write:

<template name="day">
  {{name}}
</template>

Or, if you insist:

<template name="day">
  {{this.name}}
</template>

Also:

Template.day.isItUrgent = function() {
  return this.data.important && this.data.dueToday;
};
Hubert OG
  • 19,314
  • 7
  • 45
  • 73
  • Sorry, this might have been unclear, but each bucket is actually an array of Task objects. So I think if I did that, it would error, since I'm trying to find the name attribute of an array. – Oliver Aug 29 '13 at 21:42
  • Didn't realize this referred to the input to each. Of course. Thanks! – Oliver Aug 30 '13 at 02:05