This binding is used to bind the child elements of an object in the specified object's context. This binding can also be nested with other type of bindings such as if and foreach.
Pass the object which you want to use as context for binding child elements as the parameter. Child elements will not be shown if the object or expression passed is evaluated to be null or undefined.
The expression will be re-evaluated, if the parameter provided is an observable one. Correspondingly, the child elements will be re-processed based on the refreshed context result.
Let us take a look at the following example which demonstrates the use of with binding.
Let's carry out the following steps to see how the above code works −
Save the above code in with-bind.htm file.
Open this HTML file in a browser.
There might be a situation when it is not possible to place data-binding inside a DOM element. Essential binding can still be performed with the help of container-less syntax based on the comment tags as shown in the following code.
<ul> <li>Course Info</li> <!-- ko with: currentClasses --> ... <!-- /ko --> <!-- ko with: plannedClasses --> ... <!-- /ko --> </ul>
The <!--ko--> and <!--/ko--> works as start and end markers making it a virtual syntax and binds the data as if it is a real container.