Skip to content

Instantly share code, notes, and snippets.

@copleykj
Created September 25, 2014 00:33
Show Gist options
  • Save copleykj/ab367ddf07d1eae1805a to your computer and use it in GitHub Desktop.
Save copleykj/ab367ddf07d1eae1805a to your computer and use it in GitHub Desktop.
UI.registerHelper('eachIndex', function () {
var withIndex = this.map(function(x, i) {
return {data: x, index: i}
});
return UI.Each(
function() {
return withIndex;
}, UI.block(null), UI.block(null));
});
Then you can use #eachIndex instead of #each and access the data and the index using dot notation:
<template name="myTemplate">
<ul>
{{#eachIndex myList}}
<li>Item number {{this.index}} is {{this.data}}.</li>
{{/eachIndex}}
</ul>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment