knockout.js using $index with if binding

前端 未结 2 629
梦谈多话
梦谈多话 2020-12-02 21:56

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

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 22:33

    From the knockout bindings page

    $index (only available within foreach bindings)

    This is the zero-based index of the current array entry being rendered by a foreach binding. Unlike the other binding context properties, $index is an observable and is updated whenever the index of the item changes (e.g., if items are added to or removed from the array).

    Example

    |

    Results in

    Model #: UAI5021 | Catalog #: UIOY786
    

提交回复
热议问题