2

I want to use the $index context property in a foreach binding. But it does not work for me.

I have a table which shows all persons. What I want to do is when there is more than 1 person in the list, I want to show a delete button. But the button never shows on my view. What is the problem?

<table>
        <tr>
            <th>Name</th>
            <th>Id</th>
            <th></th>
        </tr>
        <tbody data-bind="foreach:Persons">
            <tr>
                <td><span data-bind="text:Name()"></span></td>
                <td><span data-bind="text:Id()"></span></td>
                <td>
                    <!--ko if:($index > 0)-->
                    <button data-bind="click:Delete($data)}">DEL</button>
                    <!--/ko-->
                </td>
            </tr>
        </tbody>
</table>
David Tansey
  • 5,813
  • 4
  • 35
  • 51
ATAO
  • 15
  • 4

0 Answers0