JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://github.com/downloads/SteveSanderson/knockout/knockout-2.0.0.js"></script>
<!-- First Example -->
<center><h2>First Example using ViewModel</h2></center>
<ul data-bind="template: {name: 'brandsTemplate', foreach: brands}">
</ul>
<script id="brandsTemplate" type="text/html">
<li>
<input type="checkbox" data-bind="attr: {id: id, name: id}" />
<label data-bind="attr: {'for': id, title: description}, text: name" />
</li>
</script>
<!-- Second Example -->
<center><h2>How-to do the same using plain strigns array???</h2></center>
<ul data-bind="template: {name: 'rawStringsTemplate', foreach: rawBrands}">
</ul>
<script id="rawStringsTemplate" type="text/html">
<li>
<input type="checkbox"/>
<label data-bind="text: ??????" />
</li>
</script>
JavaScript
function brandEntity(id, name, description) {
return {
id: ko.observable(id),
name: ko.observable(name),
description: ko.observable(description)
};
};
var brandsFilterViewModel = {
brandsTitle: ko.observable("Brands K1O"),
brands: ko.observableArray([
new brandEntity("555", "brand 1", "br1 description"),
new brandEntity("444", "brand 2", "br2 description"),
new brandEntity("333", "brand 3", "br3 description")]),
rawBrands: ko.observableArray(["rawBrand1", "rawBrand2", "rawBrand3"])
};
ko.applyBindings(brandsFilterViewModel);