在foreach淘汰js数组中跳过项目? [英] Skip item in foreach knockout js array?
问题描述
我有一个关于淘汰赛js和第一个项目的foreach的问题。
我想跳过第一个并遍历下一个项目。
主要问题是我想要做这样的事情:
i have this question about a foreach in knockout js and the first item. I want to skip the first one and iterate over the next items.
The main issue is that i wanna do something like this:
<div data-bind="text: ItemsArray[0].someProperty"></div>
<div data-bind="foreach: ItemsArray"> <!-- here i must skip the first item -->
<div data-bind="text: someProperty"></div>
</div>
推荐答案
我不认为knockoutJS提供了跳过一个数组中的特定元素,但是可以使用一个小窍门。
I don't think knockoutJS provides a function to skip a specific element in an Array, but you can use a small trick.
如果您只想跳过第一个项目,可以使用
$ p $ lt; code>< div data-bind =text:ItemsArray [0]。 someProperty>< / DIV>
< div data-bind =foreach:ItemsArray>
<! - ko if:$ index()!= 0 - >
If you want to skip only the first item, you can use the $index
property:
< / div>
<div data-bind="text: ItemsArray[0].someProperty"></div>
<div data-bind="foreach: ItemsArray">
<!-- ko if: $index() != 0 -->
<div data-bind="text: someProperty"></div>
<!-- /ko -->
</div>
这篇关于在foreach淘汰js数组中跳过项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!