问题
so i am using knockout to bind some set of values to a grid, using the foreach something like i have below.
<table id="pcc-batch-list" class="table table-striped" >
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody data-bind="foreach:stuff">
<tr>
<td data-bind="text: Something1"></td>
<td data-bind="text: Something2"></td>
<td data-bind="text: Something3"></td>
<td data-bind="text: Something4"></td>
</tr>
</tbody>
</table>
and I want to conditionally change the color of the text displayed based on the actual value of say Something2. How would i go about doing that?
回答1:
Try css binding http://knockoutjs.com/documentation/css-binding.html remember to use () in expression.
data-bind="text: Something1, css: {colorClass: isSomething() > 0}"
来源:https://stackoverflow.com/questions/14507085/using-a-conditional-on-a-knockout-binded-value