O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Computed observables

In this section, we will discuss a special way to create complex properties that depend on our existing observable properties. The standard approach in the Knockout.js library is computed observables. We will consider these kinds of properties with a simple example.

Using a computed observable

Let's add two base observable properties in the Model (the person object) and ViewModel (the personViewModel object): firstName and lastName (PersonalPage-Computed1.html). The initial values of these properties will be John and Doe, respectively.

The Model will be as follows:

var person = {
  firstName: "John",
  lastName: "Doe"
};

The ViewModel will be as follows:

var personViewModel = function() { var self = this; self.firstName = ko.observable(person.firstName); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required