javascript - how get the current value of input on knockout focusout -


im new knockout.js. wanted value of input on focus out. focus out event trigger function change items on observable array variable.

here's code:

<input placeholder="enter caption" type="text" data-bind="event:{focusout: $parent.modifyphotocaption(id, $(this).val())}" /> 

however, $(this).val() doesn't work, nor this.val. wanted value of current input immediately.

thanks help.

update:

i think havent gave lot of details. reason why wanted value immidiately because there lot of input text:

<input placeholder="enter caption" type="text" data-bind="event:{focusout: $parent.modifyphotocaption(id, $(this).val())}" /> <input placeholder="enter caption" type="text" data-bind="event:{focusout: $parent.modifyphotocaption(id, $(this).val())}" /> <input placeholder="enter caption" type="text" data-bind="event:{focusout: $parent.modifyphotocaption(id, $(this).val())}" /> 

i don't know how values via array. , seems doing fastest

as commented on question: use observable property , subscribe it. whatever changes need in observablearray in subscribe, unless bound item part of observable array.

var vm = function() {     var self = this;      self.foo = ko.observable();      self.foo.subscribe(function() {        // whatever needed.        console.log(self.foo());      }); };  ko.applybindings(new vm()); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -