It seems that update in custom binding has stopped working (it was working in version 2.2.0).
I put alerts in events that should be triggered, and it is not working when Add button is pressed.
Can someone confirm this or give info where is the problem and what should be done?
See the working version (using KO 2.1.0) vs the broken version (using KO 2.2.0).
HTML:
<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/>
JS:
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);