Sunday, 8 September 2013

Knockout rebinding resets the HTML

Knockout rebinding resets the HTML

With knockout, if a rebinding takes place, why is the HTML reset to its
initial state? Look at the following code
(http://jsfiddle.net/mgs_jsfiddle/KNnmC/)
<div data-bind="with: person">
<p>person <input type="text" data-bind="value: firstName"/></p>
</div>
<div>
<a href="#" data-bind="click: moveNext">moveNext</a>
</div>
$(function() {
function ViewModel() {
var self = this;
self.person = ko.observable({ firstName: "first"});
self.moveNext = function() {
self.person({ firstName: "second"});
};
};
ko.applyBindings(new ViewModel());
$("input").css("background-color", "#ffff00");
});
If the anchor is clicked, the input element looses its background color.
Why isn't just the value changed?

No comments:

Post a Comment