使用带有if绑定的$ index的knockout.js [英] knockout.js using $index with if binding
本文介绍了使用带有if绑定的$ index的knockout.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图根据 $ index
的值显示一些标记,我可以显示该值,但我似乎无法使用如果
绑定,这里最好的方法是什么?
I'm trying to show some mark up based on the value of $index
, I can display the value but I can't seem to use it with an if
binding, what's the best approach here?
<!-- ko if: $index===0 -->
<div>some mark up here</div>
<!-- /ko -->
推荐答案
$ index是一个可观察的,可观察的是函数。在表达式中使用observable时,必须使用()表单来访问该值。
$index is an observable, and observables are functions. When you use observables in an expression you must use the () form to access the value.
<!-- ko if: $index() === 0 -->
这篇关于使用带有if绑定的$ index的knockout.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文