knockout.js - How to bind one html element to two observables? -


i know how bind 1 observable 2 html elements, how can bind 1 html element 2 observables 2 way binding?

the html element input textbox.

you ask binding single input field 2 observables, if model dictates 2 observables should equal, logic should in model, independent of view , bindings.

to have 2 equal observables, can make 1 plain observable , other computed observable reads , updates first one.

function viewmodel() {     this.first = ko.observable();     this.second = ko.computed({         read: this.first,         write: this.first     }); } 

then input can bound either one.

edit: if 2 properties synonyms of each other, can assign same observable both. takes advantage of observables being actual objects.

function viewmodel() {     this.second = this.first = ko.observable(); } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -