Hi,
This is because the click that you have defined is evaluated when it is parsed by knockout, meaning that the firstName("Mary") is called when the data-bind is parsed.
You can wrap the click in a function to get round this: <a href='#' data-bind="click: function(){ firstName('Mary'); }">click to change
name</a>
But, it may be neater to update your view model to have an update method and a new textbox for the new value:
<input data-bind="value: newFirstName"/>
<a href='#' data-bind="click: updateFirstName;">click to change
name</a>
function theVM() {
var self = this;
self.firstName = ko.observable('Harry');
self.lastName = ko.observable('Smith');
self.fullName = ko.computed(function(){
return self.firstName() + ' ' + self.lastName();
});
self.newFirstName = ko.observable('');
self.updateFirstName = function(){
self.firstName(self.newFirstName());
self.newFirstName('');
};
};
WARNING: this is untested code, but hopefully you get the idea.
Russell