Data bindings
Data bindings are attributes added by the framework for the purpose of data access between elements and view scope. While Observable arrays are efficient in accessing the list of objects with the number of operations on top of the display of the list using the foreach
function, Knockout.js has provided three additional data binding abilities:
- Control-flow bindings
- Appearance bindings
- Interactive bindings
Let us review these data bindings in detail in the following sections.
Control-flow bindings
As the name suggests, control-flow bindings help us access the data elements based on a certain condition. The if
, if-not
, and with
are the control-flow bindings available from the Knockout.js.
In the following example, we will be using if
and with
control-flow bindings. We have added a new attribute to the Employee
object called age
; we are displaying the age value in green only if it is greater than 20. Similarly, we have added another markedEmployee
. By this, with control-flow binding,...