xiaolizi007
11/22/2016 - 6:50 AM

From http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/kendo-mvvm-data-binding-style.html Style 绑定可以通过 ViewModel 绑定到 DOM 元素

From http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/kendo-mvvm-data-binding-style.html Style 绑定可以通过 ViewModel 绑定到 DOM 元素 CSS 风格属性


<span data-bind="style: {color: priceColor, fontWeight: priceFontWeight},
             text: price"></span>

<script>
var viewModel = kendo.observable({
    price: 42,
    priceColor: function() {
        var price = this.get("price");

        if (price <= 42) {
            return "#00ff00";
        } else {
            return "#ff0000";
        }
    },
    priceFontWeight: function() {
        var price = this.get("price");

        if (price <= 42) {
            return "bold";
        } else {
            return ""; //will reset the font weight to its default value
        }
    }
});

kendo.bind($("span"), viewModel);
</script>