Last Updated: February 25, 2016
·
2.304K
· effisfor

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.