alternate row style with $index binding

后端 未结 2 1216
遇见更好的自我
遇见更好的自我 2021-02-06 22:40

I am having trouble getting an alternate-row css class applied to a knockout template with a foreach binding context. I am using knockout 2.1 with the available $index

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 22:55

    I struggled with this for a couple minutes and found that this question hadn't really been covered since the new binding context variables (like $index)had been introduced in knockout 2.1

    The mistake I was making was that I simply forgot that $index itself is an observable, and must be unwrapped if we are using it in an expression in the data-bind attribute. ie,

  • should become

  • woops :)

提交回复
热议问题