Access two-dimensional array indexes in Meteor template
First you'll need a helper method:
Handlebars.registerHelper('each_with_index', function(cursor, options) {
var fn = options.fn, inverse = options.inverse;
var ret = "";
var idx = 0;
cursor.forEach(function(item){
idx++;
console.log(item.index);
item.index = idx;
ret+=fn(item);
});
return ret;
});
Then you'll need this for the first array:
{{#each_with_index YOUR_ARRAY}}
{{index}}
And inside that, for the second, you'll need:
{{#each_with_index YOUR_ARRAYS_ARRAY}}
{{index}} // First index
{{../../index}} // Parent index
Shout if this is baloney.
Written by Effisfor
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Handlebars
Authors
wern
18.61K
benjaminrh
9.925K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#