【问题标题】:using a conditional on a knockout binded value使用敲除绑定值的条件
【发布时间】:2013-01-08 13:09:01
【问题描述】:

所以我使用敲除将一组值绑定到网格,使用类似于我下面的 foreach。

<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>

我想根据 say Something2 的实际值有条件地更改显示的文本颜色。我该怎么做呢?

【问题讨论】:

    标签: javascript jquery knockout.js knockout-mvc


    【解决方案1】:

    尝试css绑定http://knockoutjs.com/documentation/css-binding.html记得在表达式中使用()。

    data-bind="text: Something1, css: {colorClass: isSomething() > 0}"
    

    【讨论】:

    • 我认为这是我想要的,但我遇到了一些麻烦。你能看看这个小提琴并告诉我哪里出错了吗? jsfiddle.net/nGgwB/5
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 2013-06-11
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 2012-06-06
    • 2016-04-27
    相关资源
    最近更新 更多