knockout.js - Custom parameters on knockout click binding -


i'm trying call function custom parameter, i'm unable access parameter, , observable() object instead. i'm trying retrieve index of specific element in list. point me in right direction on how so?

html:

<div id="formula">   <b>formula</b><br/>     <!-- ko foreach: formula -->       <span data-bind="text: $data, attr: {name: $index}, click: $parent.convert.bind($data,$index)"></span><br/>     <!-- /ko --> </div> 

javascript:

var listmodel = function(formula) {   var self = this;   self.formula = ko.observablearray(formula);   self.convert = function(index) {     alert(index); //this should show index of clicked element   } };  listmodel = new listmodel(formula); ko.applybindings(listmodel); 

should $parent.convert.bind($data,$index())

<div id="formula">   <b>formula</b><br/>     <!-- ko foreach: formula -->       <span data-bind="text: $data, attr: {name: $index}, click: $parent.convert.bind($data,$index())"></span><br/>     <!-- /ko --> </div> 

example


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -