using a conditional on a knockout binded value

半腔热情 提交于 2019-12-24 09:17:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!