I use KnockoutJS in my HTML to bind data to the visibility of table rows to specific observable values, as defined in my accompanying JavaScript. My table looks like this:
<table class="myTable">
<tr data-bind="if: thisRowVisible"> </tr>
<tr data-bind="if: thatRowVisible"> </tr>
<tr data-bind="if: anotherRowVisible"> </tr>
</table>
As the application starts, the table rows can be hidden or displayed using these data-bound values if. To give the table rows alternating colors (zebra / striped), in my CSS there is the following:
.myTable tr:nth-child(even) td {
background-color: black;
}
.myTable tr:nth-child(odd) td {
background-color: gray;
}
Typically, this CSS builds strings correctly. Even lines will be colored black, and odd lines will be gray. However, my problem arises when you enter Knockout data bindings.
, , Index # 2 . , , <tr> . . โ2 , , - . , .
- , KnockoutJS? - KO, <tr> Markup, CSS ?