Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created October 21, 2012 20:36
Show Gist options
  • Save mrrooijen/3928411 to your computer and use it in GitHub Desktop.
Save mrrooijen/3928411 to your computer and use it in GitHub Desktop.
Batman.js data-foreach with index.
<!-- 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>
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