javascript - options.data has multiple index elements in handlebars helper -
i have handlebars template structured this:
{{#each array}} stuff {{#each array2}} more stuff {{#customhelper}}{{/customhelper}} {{/each}} {{/each}}
each array contains 4 items.
the handlebars helper looks this:
handlebars.registerhelper('customhelper', function(options){ console.log(options.data); });
options.data
contains number of times (index
) it's been through #each
. if there multiple #each
's returns innermost one. however, want index of outermost #each
.
logging options.data
gives:
object {index: 0, index: 0} object {index: 1, index: 0} object {index: 2, index: 0} object {index: 3, index: 0} object {index: 0, index: 1} object {index: 1, index: 1} object {index: 2, index: 1} object {index: 3, index: 1} object {index: 0, index: 2} object {index: 1, index: 2} object {index: 2, index: 2} object {index: 3, index: 2} object {index: 0, index: 3} object {index: 1, index: 3} object {index: 2, index: 3} object {index: 3, index: 3}
this shows both indexes there. first index innermost #each
, second 1 outermost one. far i'm aware, shouldn't possible have 2 identical keys in javascript object.
logging options.data.index
gives first index
, not second one.
is possible access second index
, , if so, how?
i figured out. deleting index:
delete options.data.index;
will delete first one, now
options.data.index
will return index of outer #each
Comments
Post a Comment