I am trying to get index of an array in a Meteor template each loop. I referred to this and this.
This is what I done:
Template.SpaceList.helpers({
Spaces: function() {
var cursor = Spaces.find();
var array = _.map(cursor, function(doc, index) {
doc.number = index + 1;
return doc;
});
return array;
}
And this is the template:
<template name="SpaceList">
<table >
<tbody>
{{#each Spaces}}
<tr>
<td>{{number}} <a href="{{pathFor 'SpaceDetails'}}" >{{title}}</a></td>
<td><a href="{{pathFor 'EditSpace'}}" > Edit</a></td>
</tr>
{{/each}}
</tbody>
</table>
</template>
But I getting this error:
Exception in template helper: TypeError: Cannot set property 'number' of null
What is the problem?