我用这段代码得到一个奇怪的样式文本:
self.styleClass = ko.computed(function () { return self.isFollowing() ? "button" : "secondary button"; }); <button data-bind="text: followButtonText,click: toggleIsFollowing,css: styleClass"></button>
它呈现:
<button data-bind="text: followButtonText,css: styleClass" class=" 0 1 2 3 4 5 6 7 8 9 10 11 12">Unfollow</button>
model.styleClass()在控制台中渲染得很好
解决方法
css绑定的语义已从KO 2.1.0更改为KO 2.2.0
We’ve also made some features work more like you might always have
thought they should work. For example,the css binding can Now attach
programmatically-generated CSS class names to elements (prevIoUsly,it
was limited to toggling predefined CSS class names).
所以升级到KO 2.2.1,它会正常工作.
<button data-bind="text: followButtonText,attr:{ class: styleClass}" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。