获得dart聚合物重复模板中的索引

eny*_*nyo 11 dart dart-polymer

我想迭代一个可枚举的并显示一个计数器

<div template repeat="{{ name in names }}">
  ###. {{name}}
</div>
Run Code Online (Sandbox Code Playgroud)

我应该放什么,而不是###这样,它显示了名称的位置:

1. John Doe
2. Jane Doe
3. etc...
Run Code Online (Sandbox Code Playgroud)

Pix*_*ant 17

Polymer现在有能力做到这一点:

<template repeat="{{fruit in fruits | enumerate}}">
  <li>You should try the {{fruit.value}}. It is number {{fruit.index}}.</li>
</template>
Run Code Online (Sandbox Code Playgroud)

示例来自https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/iterate_loop_index/my_example.html


Wol*_*ram 7

其他解决方案在Polymer 0.3.4(不再是?)中对我不起作用,但是有关于模板的文档,包括在循环集合时的索引:

<template repeat="{{ foo, i in foos }}">
  <template repeat="{{ value, j in foo }}">
    {{ i }}:{{ j }}. {{ value }}
  </template>
</template>
Run Code Online (Sandbox Code Playgroud)