knockout.js - Update KnockoutJS bound textbox with jQuery val() -
so i'm using knockoutjs ko mapping plugin in single page app , works great... except...
there option referring site send values in query string prepopulate couple textboxes. have js function parses query string , uses jquery val() populate ko bound textbox value. however, value never gets set.
here pseudo-code on i'm trying...
var jobtitle = "ninja"; $("#jobtitle").val(jobtitle); // doesn't work $("#jobtitle").val(jobtitle).change(); // doesn't work $("#hiddenjobtitle").val(jobtitle); // works
markup
<input id="jobtitle" type="text" data-bind="value: jobtitle" /> <input id="hiddenjobtitle" type="hidden" data-bind="value: jobtitle" />
an interesting note: use same code set value of ko bound hidden field , works fine.
the reason not work $("#jobtitle").val(jobtitle)
because jobtitle knockout databind function. if inspect @ point in code , see jobtitle returning see function. need use $("#jobtitle").val(jobtitle());
in order return of knockout value.
Comments
Post a Comment