How to access the index of an item in knockout.js template

前端 未结 3 1243
悲哀的现实
悲哀的现实 2021-02-05 11:17

Within my template in tbody below, how can I access the index of the item being rendered?

3条回答
  •  无人及你
    2021-02-05 11:48

    I'm doing this and it's working pretty well. Not the best looking, but keeps everything in order:

    Use the attr: binding to set the name attribute of your field and then use $parent.CallForwards.indexOf($data) to get your index.

    data-bind="value: Name, attr: {name: 'CallForwards[' + $parent.CallForwards.indexOf($data) + '].Name'}"
    

提交回复
热议问题