I am using Knockout JS. while in the subscribe function of dropdown. I need to get the index of selected dropdown.
where as dropdown is inside table(ie foreach tr)
HTML:
<table>
<tbody data-bind="foreach: Rows">
<tr>
<td>
<select data-bind="options: Materials, value: selectedMaterial,attr:{index:$(index)}"></select>
</td>
</tr>
</table>
Script:
this.selectedMaterial.subscribe(function(data){
// I need to get the index value of the selectedMaterial
// i try to get like following code but its not working
var k =$(this).attr("index");
});
It’s impossible for KO to do that in subscribe function. You should try another way like handle change event.