Getting a pointer in a nested rudder coal loop

I added a http://mozmonkey.com/2014/03/ember-getting-the-index-in-each-loops/ blog post to add an index counter through an assistant. This works fine with a single loop. But when I use it with each loop nested, the value repeats. Example:

{{#each item in data}}
    {{#eachIndexed record in item.innerdata}}
       {{index_1}}
    {{/eachIndexed}}
{{/each}}

I have two objects in the data and two objects in each internal folder. Expected Result:

1 2 3 4

but i get

1 2 1 2

How to get the expected result? The steering version is 1.1.2 and the ember version is 1.6.1.

+4
source share
2 answers

If your data:

[
  {innerdata: ['foo', 'bar']},
  {innerdata: ['foo', 'bar']}
]

Then it works as intended, because this index is not a counter.

{{#each item in data}}
    Outer Index: {{index_1}}<br>
    {{#eachIndexed record in item.innerdata}}
       Inner Index: {{index_1}}<br>
    {{/eachIndexed}}
{{/each}}

Output:

: 1
: 1
: 2
: 2
: 1
: 2

, : fooobar.com/questions/307961/...

(function() {
  var positionCounter = 1;

  Handlebars.registerHelper('position', function() {
    return positionCounter++;
  });
})();

:

{{#each item in data}}
    {{#eachIndexed record in item.innerdata}}
       {{position}}
    {{/eachIndexed}}
{{/each}}
+3
0

Source: https://habr.com/ru/post/1599819/


All Articles