Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor iterate list in template

I have this:

Template.laps_t.laps = function () {
  return Practices.findOne({name: Session.get('practice')});
};

What do I have to do to iterate over this and put the values in paragraphs? I mean:

{{#each laps.lapList}}
  <p>WHAT DO I HAVE TO PUT HERE TO PRINT THE VALUES OF THE LIST????</p>
{{/each}}

Am I doing this right? What do I have to put inside that paragraph?

EDIT:

Thanks Justin Case, your solution did the trick.

Now I have one more problem. I want to print no only lap.lapList but also lap.lapTimeList (which is another list like [1,2,3,4,5,...]) in a table like so:

{{#each laps.lapList}}
  <tr>
    <td>iterate over and print the current value of lapList (solved using {{this}})</td>
    <td>iterate over and print the current value of lapTimeList</td>
  </tr>
{{/each}}

laps is the object that holds both lapList and lapTimeList. So, the idea is to print the lap number and the respective time. Does anyone knows how?

like image 948
jdscosta91 Avatar asked Jan 07 '13 03:01

jdscosta91


1 Answers

If laps.lapList is an array in the form of [1,2,3] then:

{{#each laps.lapList}}
  <p>{{.}}</p>
{{/each}}

{{.}} refers to the current object/element. If it contains a dictionaries/hashes e.g. [{elapsedTime:32.0, location: 'Chicago'}] then you can use the key name:

{{#each laps.lapList}}
  <p>Lap took {{elapsedTime}}</p>
{{/each}}
like image 147
Justin Case Avatar answered Oct 22 '22 23:10

Justin Case