wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

item index in rt-repeat #121

Closed t1m0n closed 8 years ago

t1m0n commented 8 years ago

Hello, is where any way to get index of item in rt-repeat? e.g.

<div rt-repeat="item in this.state.items">
     <span>Item index is {item.index} or {item._index}</span>
</div>

It would be useful for key attribute if items have no ids.

I know that I can get index this way:

<div rt-repeat="item in this.state.items" rt-scope="this.state.items.indexOf(item) as index">
     <span>Item index is {index}</span>
</div>

But I think it would be great if we could be able to get index automatically, what do you think?

Thanks.

nippur72 commented 8 years ago

if you have item in a repeat, then a variable named itemIndex will be automatically put in the scope.

t1m0n commented 8 years ago

@nippur72 Oh thanks, didn't read docs carefully, my bad.