gpt4 book ai didi

knockout.js - 设置多个类时与 $index 的 CSS 绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 23:23:44 26 4
gpt4 key购买 nike

有了这个绑定(bind)

css: 'item' + $index()

我得到这个输出
class="item0"
class="item1"
class="item2"
...

当绑定(bind)多个如下类时,我无法使用它,抛出语法错误,因为 :预计而不是 + .有什么提示吗?
css: { 'item' + $index(), 'active': $index() == 0 }

一种解决方法是使用属性绑定(bind),但如果可能的话,我想避免这种情况,因为已经设置了现有的类,所以我必须将它们包含在绑定(bind)中。
attr: { 'class': 'slider-item item' + $index() + ($index() == 0 ? ' active' : '') }

最佳答案

您也可以在 css 中执行相同的字符串连接。捆绑:

css: 'item' + $index() + ($index() == 1 ? ' active' : '')

演示 JSFiddle.

关于knockout.js - 设置多个类时与 $index 的 CSS 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17166483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com