JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://knockoutjs.com/downloads/knockout-2.2.0.js"></script>
<div data-bind="foreach: items, myBind: {}">
<h3>
<a href="#" data-bind="text: id"></a>
</h3>
<div data-bind="text: name"> </div>
</div>
<button data-bind="click: add">Add Item</button>
<hr/>
JavaScript
ko.bindingHandlers.myBind = {
init: function(element, valueAccessor) {
alert('init');
},
update: function(element, valueAccessor) {
alert('update');
}
}
function Item(id, name) {
this.id = ko.observable(id);
this.name = ko.observable(name);
}
var viewModel = {
items: ko.observableArray([
new Item(1, "one"),
new Item(2, "two"),
new Item(3, "three")]),
add: function() {
viewModel.items.push(new Item(4, "foo"));
}
};
ko.applyBindings(viewModel);