Knockout.js 使用 $index 和 if 绑定 [英] knockout.js using $index with if binding
本文介绍了Knockout.js 使用 $index 和 if 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图根据 $index
的值显示一些标记,我可以显示该值,但我似乎无法将它与 if
绑定,这里最好的方法是什么?
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,而 observables 是函数.在表达式中使用 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 -->
这篇关于Knockout.js 使用 $index 和 if 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文