Thanks to visit codestin.com
Credit goes to github.com

Skip to content

API Reference: Bindings

NickLeippe edited this page Feb 10, 2015 · 5 revisions

Back to API Reference

Alphabetical

attr
checked
click
css
disable
enable
event
foreach
hasfocus
html
if
ifnot
options
selectedOptions
style
submit
template
text
uniqueName
value
visible
with

Bindings

attr

Purpose

Set the value of any attribute of the DOM node.

Parameter

A JavaScript object in which the property names correspond to attribute names, and the values correspond to the attribute values. If an observable is referenced, the value will be updated accordingly (a one-way binding though—see checked or value for two-way bindings).

Example

<a data-bind="attr: {'href': url, 'title': linkTitle}">link text</a>

checked

Purpose

Tie the state of a checkbox or radio button form control to a view model.

Mechanisms

  • checkbox state tied to an observable
  • Pattern: control a boolean
  • Initially, the javascript thruthiness of the observable determines the checked state of the checkbox.
  • Checking it will set the observable to true.
  • Unchecking it will set the observable to false.
  • checkbox state tied to an observableArray
  • Pattern: control the inclusion of an element in a set
  • Initially, if the checkbox's value attribute is found in the array, it will be checked.
  • Checking it will add the value to the array.
  • Unchecking it will remove the value from the array.
  • radio state tied to an observable
  • Pattern: select the value of an enum (each radio representing one possible value)
  • Initially, if the radio's value attribute matches the observable's value, it will be checked.
  • Checking it will set the observable to the radio's value attribute.

Notes

Binding order affects checked. In most cases, if using the value binding together with the checked binding, you will want to specify the value binding first. E.g. data-bind="value: val, checked: checkedValue" (for both checkbox and radio buttons).

click

css

disable

enable

event

foreach

hasfocus

html

if

ifnot

options

repeat

selectedOptions

style

submit

template

text

uniqueName

value

visible

with

Clone this wiki locally