Created
October 21, 2012 20:36
-
-
Save mrrooijen/3928411 to your computer and use it in GitHub Desktop.
Batman.js data-foreach with index.
This file contains hidden or 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
<!-- Show the <hr /> if the `account.viewIndex` is greater than `0` --> | |
<!-- Note: The `gt` function is a custom filter I made, see the `helpers.js.coffee` file --> | |
<div data-foreach-account="currentUser.accounts | withIndex"> | |
<hr data-showif="account.viewIndex | gt 0" /> | |
<span data-bind="account.email"></span> | |
</div> |
This file contains hidden or 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
Batman.mixin Batman.Filters, | |
withIndex: (input) -> | |
return input unless input | |
index = -1 | |
input.forEach (data) -> data.set("viewIndex", index += 1) | |
input | |
gt: (input, value) -> input > value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment