Here is html for binding of computed properties
<p><input data-bind="value: firstValue"></p>
<p><input data-bind="value: secondValue"></p>
<p><input data-bind="value: addValue"></p>
and out model , we are using here in our model computed properties of knockout js which will be always reacts to change in the properties on the basis of this property is computed. so any change in firstValue or secondValue will also change the result of addValue computed properties.
and here is js fiddle linkfunction AppViewModel() { var self = this; self.firstValue = ko.observable(6); self.secondValue = ko.observable(5); self.addValue = ko.computed(function() { return parseInt(self.firstValue()) + parseInt (self.secondValue()); }); } // Activates knockout.js ko.applyBindings(new AppViewModel());
No comments:
Post a Comment