function item(id) {
this.id = id || ++item.cnt;
}
item.cnt = 0;
var viewModel = {
items: ko.observableArray(),
addItem: function() {
viewModel.items.push(new item());
},
removeItem: function(item) {
viewModel.items.remove(item);
}
}
ko.applyBindings(viewModel);
<button data-bind="click: addItem, clickBubble: false">Add item</button>
<div id="items" data-bind="foreach: items">
<label>Item: <input data-bind="value: id"/></label>
<button data-bind="click: $root.removeItem, clickBubble: false">Remove</button>
</div>
<button id="add">Add item</button>
<div id="items">
<label>Item: <input id="item"/></label>
<button id="remove">Remove</button>
</div>
ko.applyBindingAccessorsToNode(document.getElementById("add"), {click: viewModel.addItem}, viewModel);
ko.applyBindingAccessorsToNode(document.getElementById("items"), {foreach: viewModel.items}, viewModel);
// what now ???
--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.