knockout.js - Two way binding in knockoutjs -



knockout.js - Two way binding in knockoutjs -

i start using knockoutjs. in below code trying bind div's width in two-way.

var viewmodel = function () { this.width = ko.observable(7); }; ko.bindinghandlers.widthbinding = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var div = $(element); var value = valueaccessor(); var width = ko.utils.unwrapobservable(value); div[0].style['width'] = width + "px"; }, update: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var value = valueaccessor(); var width = ko.utils.unwrapobservable(value); div[0].style['width'] = width + "px"; } }; $("#contentdiv").enableresize(); ko.applybindings(new viewmodel()); <input data-bind="value: width" /> <div id="contentdiv" data-bind="widthbinding : width" >

in above code have 2 ui elements, 1 text input , 1 div.and can able resize div during run time. if come in number in text input means apply div's width, working fine. @ same time if resize div during run time means width should reflect in text input. there way that?

you can utilize style binding alter width :

<input data-bind="value:width ,style : { width : width()+'px' }" />

http://jsfiddle.net/gurkavcu/ghgx7/

knockout.js

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -