mikeric/rivets

Nested rv-each and indexes

Closed this issue · 3 comments

When we have nested rv-each binders, we only have one index. This index is the index of the last rv-each. So we can't us multiple indexes. See this example : https://jsfiddle.net/jccazeaux/cj48q6zq/3/
I cannot access the index of first rv-each

A simple solution would be to not use generic index attribute but a dynamic attribute. This attribute would be %<item>% where <item> represents the current iterated item (rv-each-[item])

In the jsfiddle example, we could access each index like this :

<div id="view">
  <div rv-each-array="model.twoDimensionArray">
    <div rv-each-element="array">
      <span>element #{%array%}.{%element%}  : {element}</span>
    </div>
  </div>
</div>

it'd be even better to have something like <item>Index instead of %<item>% as last one is not self-descriptive and it's one more thing to remember about rivets. People always will ask what is the difference between { var } and { %var% }. Moreover somebody possibly uses {% and %} for as options for openinig and closing rivets tags (i.e. templateDelimiters option)

Yep your argument is right. I didn't see the possible confusion with custom delimiters. It's easy to change in the pull request.
@blikblum @Leeds-eBooks Do you have an opinion?

I do think this is a valid issue, I can't decide what the best syntax would be, I do actually quite like the % because there's less chance of a collision with a dev's own property names, but I also agree that it's one more thing to remember. I've replied on the PR anyway, let's continue the discussion there.