Knockout学习笔记
Binding context
$parent
this is the view model object in the parent context.
$parents
this is an array representing all of the parent view models.
$parents[0] is the view model from the parent context(it's the same as $parent).
$root
this is the main view model object in the root context,i.e.,the topmost(最顶层) parent context.It's usually(通常) the object that was passed to ko.applyBindings.It is equivalent(相当于) to $parents[$parents.length - 1].
$component
If you're within(内) the context of a particular component template,then $component refers to the view model for that component.It's the component-specific(特定组件) equivalent to $root.In the case of nested components,$component refers to the view model for the closest(最接近) component.
This is useful,for example,if a component's template includes one or more foreach blocks in which you wish(希望) to refer to some property or function on the component view model rather than(而不是) on the current data item.
$data
This is the view model object in the current context.In the root context,$data and $root are equivalent.Inside a nested binding context, this parameter will be set to the current data item(e.g., inside a with:person binding,$data will be set to person).$data is useful when you want to reference the view model itself,rather than(而不是) a property(属性) on the view model.
$index(only available within foreach bindings)
This is the zero-based index of the current array entry being rendered(呈现) by a foreach binding.Unlike the other binding context properties,$index is an observable and is updated whenever(每当) the index of the item changes(e.g.,if items are added to or removed from the array).
$parentContext
This refers to the binding context object at the parent level.This is different from $parent,which refers to the data (not binding context) at the parent level.This is useful,for example, if you need to access the index value of an outer foreach item from an inner context(usage:$parentContext.$index).This is undefined in the root context.
$rawData
This is the raw(原始) view model value in the current context.Usually this will be the same as $data, but if the view model provided to Knockout is wrapped(包裹) in an observable, $data will be the unwrapped(拆开) view model,and $rawData will be the observable itself.
$componentTemplateNodes
If you're within the context of a particular component template,then $componentTemplateNodes is an array containing any DOM nodes that were passed to that component.This makes it easy to build components that receive template,for example a grid component that accepts a template to define its output rows.
$context
This refers to the current binding context object.This may be useful if you want to access properties of the context when they might also exist in the view model,or if you want to pass the context object to a helper function in your view model.
$element
This is the element DOM object (for virtual elements, it will be the comment DOM object) of the current binding.This can be useful if a binding needs to access an attribute of the current element.
浙公网安备 33010602011771号