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

Special addressing forms

In the Knockout.js library, there are some specific keywords you will use. Let's review their Knockout MVC analogue:

  • $parent, $parents, $root, and $parentContext: These properties allow you to refer to different data binding contexts. You don't need think about the scopes hierarchy and peculiarities of addressing between them in Knockout MVC—now every context has a name! Consider the following code snippet:
    Razor: @using (var items = ko.Foreach(m => m.Items)) { using (var subItems = items.Foreach(m => m.SubItems)) { @subItems.Html.Span(m => ko.Model.Key + " " + items.Model.Caption + " " + m.Name)<br /> } } Html: <!-- ko foreach: Items --> <!-- ko foreach: SubItems --> <span data-bind="text : $parents[1].Key()+' '+$parent.Caption()+' ...

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