Say I have an object, someObject:
{
foo: "apple",
myArray: ["abc", "def"]
}
And a template helper that looks like this (and works fine):
getArray: function(){
var self = this;
self.myArray = self.myArray || [];
return self.myArray;
}
How should I construct the html to get the array index?
I've tried:
<template name="someObject"> // takes someObject as data
{{#each getArray}}
<div class="item" data-value="{{WHAT GOES HERE?}}">{{this}}</div>
{{/each}}
</template>
In which case this
successfully returns "abc"
and "def"
. Which is good. But how can I get the index of the array to put into the attribute data-value
?
I've tried this.index
directly but it's undefined. I also tried using a helper:
<template name="someObject"> // takes someObject as data
{{#each getArray}}
<div class="item" data-value="{{getindex}}">{{this}}</div>
{{/each}}
</template>
but in this helper getIndex
when I console.log out this
I see:
String {0: "a", 1: "b", 2: "c", length: 3}
String {0: "d", 1: "e", 2: "f", length: 3}
Is it possible to get the index?