I have table generated by mustache loop that looks like this:
names.mustache
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>
#
</th>
<th>
Name
</th>
</tr>
</thead>
<tbody>
{{#allnames}}
{{#active}}
<tr>
<td>
{{count}}
</td>
<td>
{{name}}
</td>
</tr>
{{/active}}
{{/allnames}}
</tbody>
</table>
And I want to iterate count so that my table can have row numbers. basically, i initialized $count=1
. How can I implement that with clean efficient code? or is there a better simpler way?
UPDATED For Mustache, you need to create a function
var data = {
items: allnames,
, index: function() {
return ++window['index']||(window['index']=0);
}
}
and then use {{index}}
inside the loop
originally
Sorry, I was thinking of handlebars which works as below (see correct answer above)
Use {{@index}}
{{#allnames}}
{{name}} is {{@index}}
{{/allnames}}
Note: index starts from zero