Add striped styling to a list of items

前端 未结 6 974
执笔经年
执笔经年 2021-02-01 17:43

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 removi

6条回答
  •  独厮守ぢ
    2021-02-01 17:50

    You could use the {{if}} and {{else}} conditional statements inside the template to set the class of the div.

    Also you will need to extend your View Model to include a function which returns the index of your current item, which would tell you whether it's odd or even. (Something like this)

提交回复
热议问题