I'm trying to use knockout.js with the ES5 plugin, but I'm not able to get deleting from an array to work.
It seems to work somewhat, you can delete, but there is always one item left in the array, but not really somehow. I'm totally confused why this doesn't work like you'd think it would.
What am I doing wrong?
(I have a more complex scenario that is using a durandal widget, but I was able to boil it down to just this, so I think the es5 plugin is the culprit)
Here is my markup:
<div data-bind="foreach: staffList" style="border:1px solid black;">
<div style="border: 1px solid red;">
<p data-bind="text: Name"></p>
<p>
<button data-bind="click: deleteClickHandler">Delete</button>
</p>
</div>
</div>
and script:
function ctor(){
var self=this;
self.staffList = [{Name:'one'},{Name:'two'},{Name:'three'},{Name:'four'}];
ko.track(self.staffList, { deep: true });
self.deleteClickHandler = function (obj) {
//TODO show confirm dialog first
var index = self.staffList.indexOf(obj);
if (index >= 0) {
self.staffList.splice(index, 1);
}
};
}
ko.applyBindings(ctor);
only other difference in the real world is that I'm getting the data from an API call, but the behavior is the same.