我有一个使用knockout绑定的表数据。在这里,我有像孩子一样的行。 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>
此处,Location和EmployeeRole下拉列表是子项,可以在父项中多次出现。因此,在设置选项卡索引时,我使用了'$ parentContext。$ index',但在运行时,对于所有子控件,我得到tabindex ='NAN'
我也尝试过使用$ parent.index(),但没有运气。
感谢一些帮助
答案 0 :(得分:3)
您应该使用$parentContext.$index()
而不是$parent.index()
:
<select data-bind="options:Locations, value:Location, optionsText: 'Name', optionsValue: 'ID', attr:{tabindex: 49 * ($parentContext.$index() + 1) }" >
</select>
以下是工作示例:http://jsfiddle.net/CVL4q/