knockout.js - setting tab index for children in knockout binding -
i have table data bound using knockout. here, have parent-child rows. e.g.
<tr> <td> <select data-bind="value:required, enable:requiredactive, attr:{tabindex: 43 * ($index() + 1) }"> <option value="e">eligible</option> <option value="o">on</option> <option value="f">off</option> </select> </td> <td> <input data-bind="value:setuptime, attr: { title: tabindex: 44 * ($index() + 1) }"/> <input data-bind="value:closetime, attr: { title: tabindex: 45 * ($index() + 1) }" /> </td> <td> <table> <tbody data-bind="foreach: worksegments"> <tr> <td> <select data-bind="options:locations, value:location, optionstext: 'name', optionsvalue: 'id', attr:{tabindex: 49 * ($parentcontext.$index + 1) }" > </select> </td> </tr> </tbody> </table> </td> <td> <table> <tbody data-bind="foreach: worksegments"> <tr> <td> <select class="combobox" data-bind="options:employeeroles, value:role, optionstext: 'name', optionsvalue: 'id', attr:{tabindex: 49 * ($parentcontext.$index + 1)}" > </select> </td> </tr> </tbody> </table> </td> </tr>
here, location , employeerole drop downs children , can occur multiple times within parent. therefore when setting tab index i've used '$parentcontext.$index', @ runtime, child controls tabindex='nan'
i've tried $parent.index(), no luck.
appreciate help
you should use $parentcontext.$index()
not $parent.index()
:
<select data-bind="options:locations, value:location, optionstext: 'name', optionsvalue: 'id', attr:{tabindex: 49 * ($parentcontext.$index() + 1) }" > </select>
here working example: http://jsfiddle.net/cvl4q/
Comments
Post a Comment