I want to iterate over an enumerable and display a counter
<div template repeat="{{ name in names }}">
###. {{name}}
</div>
What should I put instead of ###
so it shows the position of the name:
1. John Doe
2. Jane Doe
3. etc...
Polymer now has the ability to do this:
<template repeat="{{fruit in fruits | enumerate}}">
<li>You should try the {{fruit.value}}. It is number {{fruit.index}}.</li>
</template>
Example taken from https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/iterate_loop_index/my_example.html
The other solutions do not work for me in Polymer 0.3.4 (anymore?), but there is documentation on templates, including indexing while looping over a collection:
<template repeat="{{ foo, i in foos }}">
<template repeat="{{ value, j in foo }}">
{{ i }}:{{ j }}. {{ value }}
</template>
</template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With