I want add some methods. And this directive can’t help me.
var viewModel = function () {
firstName = ko.observable("Mike");
lastName = ko.observable("Rassel")
//fullName = ko.computed(function () {
//return firstName() + " " + lastName(); }, viewModel);
}
viewModel.fullName = ko.computed(function () {
return this.firstName() + " " + this.lastName(); }, viewModel);
DEMO: http://jsfiddle.net/gJUqK/
On local with 2.1.0 its work.
The
firstName,lastNameandfullNameshould be properties of themyViewModelinstance.This will work, as explained in the documentation. The
selfis added, because inside thefullNameobservable callback functionthiswould point to something else.Working here: http://jsfiddle.net/gJUqK/1/