knockout.js calling custom binding function -
i've found unusual code, don't understand how call custom binding function , how supposed work. here code:
viewmodel:
ko.bindinghandlers.test = function ($) { return { init: function (el, valueaccessor, bindingsaccessor, viewmodel) { }, update: function (el, valueaccessor, bindingsaccessor, viewmodel) { } } }
view:
<input type="text" data-bind="test: ???, value: 0, settings: { test: 'test-value' }">
your code wrong since have have closure scope need todo
ko.bindinghandlers.test = (function ($) { return { init: function (el, valueaccessor, bindingsaccessor, viewmodel) { }, update: function (el, valueaccessor, bindingsaccessor, viewmodel) { } } })(jquery);
edit: in markup bind test member on viewmodel like
<input type="text" data-bind="test: mymember />
to access binding custom binding
init: function (el, valueaccessor, bindingsaccessor, viewmodel) { var value = ko.utils.unwrapobservable(valueaccessor()); }
Comments
Post a Comment