JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://knockoutjs.com/js/jquery-1.4.2.min.js"></script>
<script src="https://raw.github.com/SteveSanderson/knockout/master/build/output/knockout-latest.js"></script>
<h2>Knockout Template example</h2>
<p>Based on a <a href="https://groups.google.com/forum/#!searchin/knockoutjs/template$20employee/knockoutjs/KQpBfdwxdxg/Zt_5E6bzLRMJ">discussion</a> this example should demonstrate the <a href="http://knockoutjs.com/documentation/template-binding.html">template binding</a> features of knockout.</p>
<ul data-bind='template: { name: displayMode,
foreach: employees }'> </ul>
<script id="active" type="text/html">
<li><b><span data-bind="text: name"></span>,<span data-bind="text:
active"></span></b></li>
</script>
<script id="inactive" type="text/html">
<li><i><span data-bind="text: name"></span>,<span data-bind="text:
active"></span></i></li>
</script>
<!--
other examples on jsfiddle
-->
<div class="playground">
<p>I am still learning knockout so this acts as my playground to get the hang of it. You can find many of my learning steps here on jsfiddle:</p>
<ul>
<li><a href="http://jsfiddle.net/PESyr/18/">Shopping Cart Demo<a/></li>
<li><a href="http://jsfiddle.net/BPmUx/9/">Adding a css class<a/></li>
<li><a href="http://jsfiddle.net/UxJMY/2">Using templates<a/></li>
<li><a href="http://jsfiddle.net/hy4RP/27/">Employee templates<a/></li>
<li><a href="http://jsfiddle.net/SF8LN/23/">Using medialize jquery ContextMenu as a split button</a></li>
</ul>
<p>The links above may have a newer version so you could check for that by increasing the number at the end of the uri.</p>
</div>
CSS
ul { padding: 2ex;}
.playground { font-size: 12px; color: grey; margin: 4em 2em 0 2em;}
JavaScript
var empList = [];
empList[0] = { name: "Billy", active: ko.observable(true)};
empList[1] = { name: "Jean", active: ko.observable(false)};
empList[2] = { name: "is not my ", active: ko.observable(false)};
empList[3] = { name: "Lover ", active: ko.observable(true)};
var viewModel = {
employees: ko.observableArray(empList),
displayMode: function(employee) {
return employee.active() ? "active" : "inactive";
}
};
ko.applyBindings(viewModel);
// ... then later ...
viewModel.employees.push({ name: "but the kid ", active: ko.observable(false)});
viewModel.employees.push({ name: "is not my son ", active: ko.observable(true)});