Created
September 25, 2014 00:33
-
-
Save copleykj/ab367ddf07d1eae1805a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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