December 2014
Intermediate to advanced
102 pages
1h 45m
English
Knockout maintains a parent/child hierarchy of contexts. When you are accessing properties to data bind, everything is relative to the context you are in. The root context is the ViewModel that was supplied to the ko.applyBindings function.
Everything is relative to the current context, which is why the text bindings used the name property without the prefix of the ViewModel.
In the following examples, some of the new data bindings create a child context under the root context.
Knockout offers several useful variables that allow you to navigate between the context you are in to a parent or even the root context:
$root$parent$parents$parent variable except that it contains an array of parent contexts to the context you are currently in. $parents[0] is the same as $parent. Similarly, using $parents[$parents.length - 1] is the same as using $root.$data$indexforeach binding and contains an integer that represents the current position of ...Read now
Unlock full access