What would be the best way to stripe a list with KnockoutJS? The class on the div below should be even or odd depending where it is in the list, and update when adding or removing items.
<div class="Headlines loader"
data-bind="css: { loader: headlines().length == 0 },
template: { name: 'recentHeadlinesTemplate',
foreach: beforeHeadlineAddition,
beforeRemove: function(elem) { $(elem).slideUp() },
afterAdd: slideDown }">
</div>
<script type="text/html" id="recentHeadlinesTemplate">
<div class="even">
${Title}
</div>
</script>
There was a topic for this on the KO forums a while back here: https://groups.google.com/d/topic/knockoutjs/cJ2_2QaIJdA/discussion
The solution that I had was a custom binding. There were a couple variations on it, but it basically would look like:
and be used like:
Sample here with 3 variations of this binding:
http://jsfiddle.net/rniemeyer/HJ8zJ/