简体   繁体   中英

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?

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 eg [{elapsedTime:32.0, location: 'Chicago'}] then you can use the key name:

{{#each laps.lapList}}
  <p>Lap took {{elapsedTime}}</p>
{{/each}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM