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

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -