Access index of $parent in knockout.js

前端 未结 2 1731
离开以前
离开以前 2020-12-12 18:39

In knockout.js 2.1.0, in a template using the foreach binding, you can access the current item\'s index though the $index() function. In a nested foreach binding, is there a

相关标签:
2条回答
  • 2020-12-12 19:23

    The easiest way you can find out is download "knockout context" for chrome. This shows you what data is bound to what element and also lets you see the available functions/variables to that particular bound element. It's an amazing tool for situations like these.

    0 讨论(0)
  • to access the index of the parent object use

    $parentContext.$index()
    

    rather than

    $parent.index()
    
    0 讨论(0)
提交回复
热议问题