How to access parent @index value in each-loop?
Tried the following:
{{#each company}}
{{#each employee}}
{{../@index}} // how to access company in
registe an Helper method:
Handlebars.registerHelper('eachWithIndex', function(cursor, options) {
var fn = options.fn, inverse = options.inverse;
var ret = "";
var idx = -1;
//console.log(cursor);
cursor.forEach(function(item){
idx++;
console.log(item.index);
item.index = idx;
ret+=fn(item);
});
return ret;
});
handlebars template:
{{#eachWithIndex outer}}
{{#each inner}}
{{../index}} // access outer index like this. I used hanlebars V1.3.0
{{index}} // access inner index
{{/each}}
{{/eachWithIndex}}