javascript - Knockout bind multiple observables to a single custom bindingHandler -


i'm trying figure out if it's possible bind 2 observables single custom binding. following snippet works i'd expect single observable:

markup:

column: <select data-bind="options: $root.columndetails,     value: column,     optionstext: 'name',     values: name,     optionscaption: 'select column...'"></select>  operator: <select data-bind="options: $root.operators,     value: operator,     optionstext: 'displayname',     values: name,     optionscaption: 'select operator...'"></select>  values: <input type="text" data-bind="expressionvalues: operator"> 

javascript:

ko.bindinghandlers.expressionvalues = {     init: function (element, valueaccessor, allbindingsaccessor, viewmodel) {          // stuff      },     update: function (element, valueaccessor, allbindingsaccessor, viewmodel) {          // stuff      } } 

the above code works expected, firing update event of custom binding when value of operator drop down changed. however, desired result bind both of selects binding handler , have update fire when either 1 changed.

i tried setting way update event doesn't fire either:

values: <input type="text" data-bind="expressionvalues: [ operator, column ]"> 

any ideas on how might achieve this?

you try passing object observables binding this:

<input type="text" data-bind="expressionvalues: { valueoperator: operator, valuecolumn }"> 

and reference them through valueaccessor in binding handler functions this:

ko.bindinghandlers.expressionvalues = {         init: function (element, valueaccessor, allbindingsaccessor, viewmodel) {                    var parameters = ko.utils.unwrapobservable(valueaccessor());              var operator = ko.utils.unwrapobservable(settings.valueoperator);             var column = ko.utils.unwrapobservable(settings.valuecolumn);              // stuff          },         update: function (element, valueaccessor, allbindingsaccessor, viewmodel) {             var parameters = ko.utils.unwrapobservable(valueaccessor());              var operator = ko.utils.unwrapobservable(settings.valueoperator);             var column = ko.utils.unwrapobservable(settings.valuecolumn);              // stuff          }     } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -