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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -