Bindings enhancements
- The
css
binding accepts multiple classes in a string and dynamic class names. - The
text
binding can be used in virtual elements:<!--ko text: myValue--><!--/ko-->
- For the
options
binding, it will skip destroyed items (unlessoptionsIncludeDestroyed
is passed as truthy),optionsValue
can accept a function just likeoptionsText
, andoptionsCaption
can be an observable. - The
with
binding will bind to the original child DOM elements when its initial value is truthy, and keep a copy of the elements as a template. - The
if
andifnot
bindings will bind to the original child DOM elements when the initial value is truthy forif
or falsy forifnot
. Additionally, they will only re-render the content when the truthiness of the value changes. - The
attr
binding handles the name attribute properly in older versions of IE.
Computed observable and binding dependency enhancements
- Observables (including computed) include a
peek
function for access within a computed without adding a dependency. observableArray
mutation functions no longer cause a dependency within a computed.- Writes to writable computeds can now be chained like observables.
- Computed observables now have an
isActive
function that indicates that the computed has dependencies (can be triggered again). change
(normal manual subscription) andbeforeChange
callbacks no longer create dependencies.
foreach
and template
enhancements
- When a function is used for the template name, it now receives the binding context as the second argument.
- The
foreach
functionality now does its best to understand items that were moved and move their content rather than re-render them. beforeMove
andafterMove
callbacks can now be configured when usingforeach
functionality.- The
foreach
andtemplate
bindings now accept anas
option to give$data
an alias. - The
afterRender
,beforeRemove
,afterAdd
,beforeMove
, andafterMove
callbacks will no longer cause dependencies.
Other binding enhancements
- The
ko
object is now available from within bindings, even ifko
is not global, such as when used with an AMD loader. - Can access the current element in a binding using the
$element
variable. - Can access the current context directly in a binding using the
$context
variable.